Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package perl-YAML-Tidy for openSUSE:Factory checked in at 2024-01-19 23:02:09 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-YAML-Tidy (Old) and /work/SRC/openSUSE:Factory/.perl-YAML-Tidy.new.16006 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-YAML-Tidy" Fri Jan 19 23:02:09 2024 rev:3 rq:1139884 version:0.9.0 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-YAML-Tidy/perl-YAML-Tidy.changes 2024-01-07 21:40:16.259950780 +0100 +++ /work/SRC/openSUSE:Factory/.perl-YAML-Tidy.new.16006/perl-YAML-Tidy.changes 2024-01-19 23:02:25.782541373 +0100 @@ -1,0 +2,12 @@ +Fri Jan 19 03:09:09 UTC 2024 - Tina Müller <timueller+p...@suse.de> + +- updated to 0.9.0 + see /usr/share/doc/packages/perl-YAML-Tidy/Changes + + v0.9.0 2024-01-18 21:45:25+01:00 + + - Add option --batch + - Add option --verbose + - Add yamltidy.pod + +------------------------------------------------------------------- Old: ---- YAML-Tidy-v0.8.0.tar.gz New: ---- YAML-Tidy-v0.9.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-YAML-Tidy.spec ++++++ --- /var/tmp/diff_new_pack.D305t4/_old 2024-01-19 23:02:26.406564199 +0100 +++ /var/tmp/diff_new_pack.D305t4/_new 2024-01-19 23:02:26.410564345 +0100 @@ -18,7 +18,7 @@ %define cpan_name YAML-Tidy Name: perl-YAML-Tidy -Version: 0.8.0 +Version: 0.9.0 Release: 0 License: Artistic-1.0 OR GPL-1.0-or-later Summary: Tidy YAML files @@ -32,14 +32,14 @@ BuildRequires: perl(Test::Deep) BuildRequires: perl(Test::More) >= 0.98 BuildRequires: perl(Test::Warnings) >= 0.029 -BuildRequires: perl(YAML::LibYAML::API) >= v0.14.0 +BuildRequires: perl(YAML::LibYAML::API) >= 0.14.0 BuildRequires: perl(YAML::LibYAML::API::XS) BuildRequires: perl(YAML::PP::Common) BuildRequires: perl(YAML::PP::Highlight) BuildRequires: perl(YAML::PP::Parser) BuildRequires: perl(experimental) Requires: perl(Getopt::Long::Descriptive) -Requires: perl(YAML::LibYAML::API) >= v0.14.0 +Requires: perl(YAML::LibYAML::API) >= 0.14.0 Requires: perl(YAML::LibYAML::API::XS) Requires: perl(YAML::PP::Common) Requires: perl(YAML::PP::Highlight) ++++++ YAML-Tidy-v0.8.0.tar.gz -> YAML-Tidy-v0.9.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/Changes new/YAML-Tidy-v0.9.0/Changes --- old/YAML-Tidy-v0.8.0/Changes 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/Changes 2024-01-18 21:46:45.000000000 +0100 @@ -1,5 +1,11 @@ Revision history for Perl module YAML::Tidy +v0.9.0 2024-01-18 21:45:25+01:00 + + - Add option --batch + - Add option --verbose + - Add yamltidy.pod + v0.8.0 2024-01-05 22:38:36+01:00 - Fix tidying unicode files diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/MANIFEST new/YAML-Tidy-v0.9.0/MANIFEST --- old/YAML-Tidy-v0.8.0/MANIFEST 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/MANIFEST 2024-01-18 21:46:45.000000000 +0100 @@ -19,12 +19,16 @@ etc/serialize-aliases/example1.yaml.tdy etc/serialize-aliases/example2.yaml etc/serialize-aliases/example2.yaml.tdy +etc/spec.yaml etc/tags.yaml lib/YAML/Tidy.pm lib/YAML/Tidy/Config.pm lib/YAML/Tidy/Node.pm +lib/YAML/Tidy/Run.pm +lib/yamltidy.pod t/00.compile.t t/01.basic.t +t/02.run.t t/10.yts.t t/11.options.t t/12.config.t @@ -56,6 +60,7 @@ t/data/foo.yaml t/data/indent.yaml t/data/plain.yaml +t/data/run.yaml t/data/trailing.yaml t/libyaml.skip t/yamltidy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/META.json new/YAML-Tidy-v0.9.0/META.json --- old/YAML-Tidy-v0.8.0/META.json 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/META.json 2024-01-18 21:46:45.000000000 +0100 @@ -62,31 +62,35 @@ "provides" : { "YAML::Tidy" : { "file" : "lib/YAML/Tidy.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Config" : { "file" : "lib/YAML/Tidy/Config.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Node" : { "file" : "lib/YAML/Tidy/Node.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Node::Alias" : { "file" : "lib/YAML/Tidy/Node.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Node::Collection" : { "file" : "lib/YAML/Tidy/Node.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Node::Leaf" : { "file" : "lib/YAML/Tidy/Node.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" }, "YAML::Tidy::Node::Scalar" : { "file" : "lib/YAML/Tidy/Node.pm", - "version" : "v0.8.0" + "version" : "v0.9.0" + }, + "YAML::Tidy::Run" : { + "file" : "lib/YAML/Tidy/Run.pm", + "version" : "v0.9.0" } }, "release_status" : "stable", @@ -100,7 +104,7 @@ "web" : "https://github.com/perlpunk/yamltidy" } }, - "version" : "v0.8.0", + "version" : "v0.9.0", "x_generated_by_perl" : "v5.30.3", "x_serialization_backend" : "Cpanel::JSON::XS version 4.26", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/META.yml new/YAML-Tidy-v0.9.0/META.yml --- old/YAML-Tidy-v0.8.0/META.yml 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/META.yml 2024-01-18 21:46:45.000000000 +0100 @@ -23,25 +23,28 @@ provides: YAML::Tidy: file: lib/YAML/Tidy.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Config: file: lib/YAML/Tidy/Config.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Node: file: lib/YAML/Tidy/Node.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Node::Alias: file: lib/YAML/Tidy/Node.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Node::Collection: file: lib/YAML/Tidy/Node.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Node::Leaf: file: lib/YAML/Tidy/Node.pm - version: v0.8.0 + version: v0.9.0 YAML::Tidy::Node::Scalar: file: lib/YAML/Tidy/Node.pm - version: v0.8.0 + version: v0.9.0 + YAML::Tidy::Run: + file: lib/YAML/Tidy/Run.pm + version: v0.9.0 requires: Cwd: '0' Data::Dumper: '0' @@ -62,7 +65,7 @@ resources: bugtracker: https://github.com/perlpunk/yamltidy/issues repository: https://github.com/perlpunk/yamltidy -version: v0.8.0 +version: v0.9.0 x_generated_by_perl: v5.30.3 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/Makefile.PL new/YAML-Tidy-v0.9.0/Makefile.PL --- old/YAML-Tidy-v0.8.0/Makefile.PL 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/Makefile.PL 2024-01-18 21:46:45.000000000 +0100 @@ -46,7 +46,7 @@ "Test::Warnings" => "0.029", "YAML::LibYAML::API" => "0.14.0" }, - "VERSION" => "v0.8.0", + "VERSION" => "v0.9.0", "test" => { "TESTS" => "t/*.t" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/README.md new/YAML-Tidy-v0.9.0/README.md --- old/YAML-Tidy-v0.8.0/README.md 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/README.md 2024-01-18 21:46:45.000000000 +0100 @@ -1,24 +1,18 @@ # yamltidy - Automatic cleanup of YAML files -This project is very new - a lot will change. - yamltidy is a formatter for YAML files. It's is inspired by the great tools [yamllint](https://yamllint.readthedocs.io/en/stable/) and [perltidy](https://metacpan.org/pod/Perl::Tidy). -yamllint is based in PyYAML and checks indentation, trailing spaces -and more, based on your configuration. - -perltidy takes perl programs and reformats the code. +* yamllint checks YAML files and reports errors and warnings. +* perltidy automatically reformats perl programs +* yamltidy automatically reformats YAML files -yamltidy will take a configuration (YAML) file like yamllint, and fix -indentation inconsistencies, trailing spaces and more. - -It is based on [C libyaml](https://github.com/yaml/libyaml) and -[perl YAML::LibYAML::API](https://metacpan.org/pod/YAML::LibYAML::API). +## Usage +``` % yamltidy foo.yaml --- a: # a comment @@ -27,9 +21,9 @@ # inplace - directly write result into original file yamltidy --inplace foo.yaml +``` -You can find results for several configurations here: -[perlpunk.github.io/yamltidy](https://perlpunk.github.io/yamltidy) +Complete documentation of options: [yamltidy.pod](lib/yamltidy.pod) ## Installation @@ -46,14 +40,16 @@ # faster without running tests % cpanm --notest YAML::Tidy -If you just want to play with it, but don't want to install it globally, -use this: +### Local installation + +If you just want to play with it, but don't want to install it globally on your +system, use this: % cpanm -l ~/localyamltidy YAML::Tidy % export PERL5LIB=~/localyamltidy/lib/perl5 % PATH=~/localyamltidy/bin:$PATH -### Use Docker Image +### Use Container Image % docker pull perlpunk/yamltidy % docker run -i --rm perlpunk/yamltidy yamltidy - < in.yaml @@ -70,63 +66,43 @@ You can pass the configuration file via the `-c`/`--config-file` switch. -The default config: [.yamltidy](.yamltidy) +The default config: + + --- + v: v0.1 + indentation: + spaces: 2 + block-sequence-in-mapping: 0 + trailing-spaces: fix + header: true + scalar-style: + default: plain + adjacency: 0 An indentation of two spaces is recommended. Sequences will by default be zero-indented, because the hyphen `-` counts as indentation. The option `block-sequence-in-mapping` can influence that. -The best output for 4 spaces is subject to discussion for a lot of test cases. - -## Usage - -### Tidy a file and print to stdout - - % cat in.yaml - --- - a: - b: - c: d - % yamltidy in.yaml - --- - a: - b: - c: d - -### Tidy content from stdin - - % echo '--- - a: - b: - c: d' | yamltidy - - --- - a: - b: - c: d +More detailed information on configuration will follow. +You can find examples for several configurations here: +[perlpunk.github.io/yamltidy](https://perlpunk.github.io/yamltidy) -### Tidy a file and save the result back - % yamltidy --inplace in.yaml - % cat in.yaml - --- - a: - b: - c: d +## Utils -### Mappings for vim +## Mappings for vim +Type `<leader>yt` to tidy the whole buffer: :noremap <leader>yt :%!yamltidy -<CR> -Type `<leader>yt` to tidy the whole buffer - - :vnoremap <leader>yt :!yamltidy --partial -<CR> - Visually select lines and type `<leader>yt`. The first level of indentation spaces will be kept. + :vnoremap <leader>yt :!yamltidy --partial -<CR> + ## Tests yamltidy tests are using the [YAML Test @@ -135,3 +111,8 @@ The tests currently make sure that at least the yamltidy output semantically matches the input. +## Implementation + +yamltidy is based on [C libyaml](https://github.com/yaml/libyaml) and +[the perl binding YAML::LibYAML::API](https://metacpan.org/pod/YAML::LibYAML::API). + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/bin/yamltidy new/YAML-Tidy-v0.9.0/bin/yamltidy --- old/YAML-Tidy-v0.8.0/bin/yamltidy 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/bin/yamltidy 2024-01-18 21:46:45.000000000 +0100 @@ -1,87 +1,8 @@ #!/usr/bin/perl -use strict; use warnings; -use 5.010; -use YAML::Tidy; -use YAML::Tidy::Config; -use YAML::LibYAML::API; -use Getopt::Long::Descriptive; -use Encode; +use v5.20; +use YAML::Tidy::Run; -our $VERSION = 'v0.8.0'; # VERSION +our $VERSION = 'v0.9.0'; # VERSION -my ($opt, $usage) = describe_options( - 'yamltidy %o file(s)', - [ 'config-file|c=s' => 'Config file' ], - [ 'config-data|d=s' => 'Configuration as a string' ], - [ 'inplace|i' => 'Edit file inplace' ], - [ 'debug' => 'Debugging output' ], - [ 'partial' => 'Input is only a part of a YAML file' ], - [ 'indent=i' => 'Override indentation spaces from config' ], - [], - [ 'help|h', "print usage message and exit", { shortcircuit => 1 } ], - [ 'version', "Print version information", { shortcircuit => 1 } ], -); -print($usage->text), exit if $opt->help; -my @versions = ( - YAML::Tidy->VERSION, YAML::PP->VERSION, - YAML::LibYAML::API->VERSION, - YAML::LibYAML::API::XS::libyaml_version -); -if ($opt->version) { - printf <<'EOM', @versions; -yamltidy: %s -YAML::PP: %s -YAML::LibYAML::API: %s -libyaml: %s -EOM - exit; -} - -my ($file) = @ARGV; -unless (defined $file) { - print $usage->text; - exit; -} -my $yaml; -if ($file eq '-') { - $yaml = decode_utf8 do { local $/; <STDIN> }; -} -else { - open my $fh, '<:encoding(UTF-8)', $file or die "Could not open '$file': $!"; - $yaml = do { local $/; <$fh> }; - close $fh; -} - -my $cfg = YAML::Tidy::Config->new( - configfile => $opt->config_file, - configdata => $opt->config_data, - indentspaces => $opt->indent, -); -my $yt = YAML::Tidy->new( - cfg => $cfg, - partial => $opt->partial, -); -if ($opt->debug) { - say "# Before:"; - print encode_utf8 $yt->highlight($yaml); -} - -my $out = $yt->tidy($yaml); - -if ($opt->inplace) { - open my $fh, '>:encoding(UTF-8)', $file or die $!; - print $fh $out; - close $fh; -} -else { - if ($opt->debug) { - } - else { - print encode_utf8 $out; - } -} -if ($opt->debug) { - say "# After:"; - print encode_utf8 $yt->highlight($out); -} +YAML::Tidy::Run->new->run; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/dist.ini new/YAML-Tidy-v0.9.0/dist.ini --- old/YAML-Tidy-v0.8.0/dist.ini 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/dist.ini 2024-01-18 21:46:45.000000000 +0100 @@ -4,7 +4,7 @@ copyright_holder = Tina Müller copyright_year = 2024 -version = v0.8.0 +version = v0.9.0 [@Filter] -bundle = @Basic diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/etc/docker/Dockerfile.base new/YAML-Tidy-v0.9.0/etc/docker/Dockerfile.base --- old/YAML-Tidy-v0.8.0/etc/docker/Dockerfile.base 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/etc/docker/Dockerfile.base 2024-01-18 21:46:46.000000000 +0100 @@ -10,5 +10,5 @@ wget \ && true -COPY install-yamltidy.sh /install-yamltidy.sh +#COPY install-yamltidy.sh /install-yamltidy.sh diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/etc/docker/install-yamltidy.sh new/YAML-Tidy-v0.9.0/etc/docker/install-yamltidy.sh --- old/YAML-Tidy-v0.8.0/etc/docker/install-yamltidy.sh 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/etc/docker/install-yamltidy.sh 2024-01-18 21:46:46.000000000 +0100 @@ -3,4 +3,4 @@ set -ex HOME=/tmp/home -cpanm -l /tmp/yamltidy --notest YAML::Tidy@0.007 +cpanm -l /tmp/yamltidy --notest YAML::Tidy@v0.8.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/etc/spec.yaml new/YAML-Tidy-v0.9.0/etc/spec.yaml --- old/YAML-Tidy-v0.8.0/etc/spec.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/etc/spec.yaml 2024-01-18 21:46:46.000000000 +0100 @@ -0,0 +1,108 @@ +--- +name: yamltidy +appspec: { version: 0.001 } +title: Reformat YAML files +format: pod +description: | + This script checks YAML files according to a configuration and automatically + reformats them. + It will output the formatted code on standard output, or edit the file + directly. + + + =head1 EXAMPLES + + =over + + =item Tidy a file and print to stdout + + % cat in.yaml + --- + a: + b: + c: d + % yamltidy in.yaml + --- + a: + b: + c: d + + =item Tidy content from stdin + + % echo '--- + a: + b: + c: d' | yamltidy - + --- + a: + b: + c: d + + + =item Tidy a file and save the result back + + % yamltidy --inplace in.yaml + % cat in.yaml + --- + a: + b: + c: d + + =item Process a list of files from stdin + + # Tidy all .yaml files that are in git + % git ls-files | grep '.yaml$' | yamltidy --inplace --batch - + # short options + % git ls-files | grep '.yaml$' | yamltidy -i -b - + # Only tidy modified files + % git ls-files --modified | grep '.yaml$' | yamltidy --inplace --batch - + + In the future yamltidy can take a directory as an argument and process + file name patterns from configuration. + + =item Use a certain configuration file + + % yamltidy -c /path/to/yamltidy.yaml file.yaml + + =item Partial formatting + + From within an editor you can pass only a part of the file on stdin. + This is important for keeping the indentation of that part. Also + it won't add a C<---> header. Compare: + + % echo ' + a: + b: c' | yamltidy - + --- + a: + b: c + % echo ' + a: + b: c' | yamltidy --partial - + + a: + b: c + + Vim example configuration: + + # :noremap <leader>yt :%!yamltidy -<CR> + # :vnoremap <leader>yt :!yamltidy --partial -<CR> + + =back + +options: +- config-file|c=s --Config file +- config-data|d=s --Configuration as a string +- inplace|i --Edit file inplace +- debug --Debugging output +- partial --Input is only a part of a YAML file +- indent=i --Override indentation spaces from config +- batch|b --Tidy all files - currently requires parameter "-" for filenames passed via STDIN +- verbose --Output information +- help|h --print usage message and exit +- version --Print version information + +parameters: +- name: file + summary: File + type: file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Config.pm new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Config.pm --- old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Config.pm 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Config.pm 2024-01-18 21:46:46.000000000 +0100 @@ -5,7 +5,7 @@ use experimental qw/ signatures /; package YAML::Tidy::Config; -our $VERSION = 'v0.8.0'; # VERSION +our $VERSION = 'v0.9.0'; # VERSION use Cwd; use YAML::PP::Common qw/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Node.pm new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Node.pm --- old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Node.pm 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Node.pm 2024-01-18 21:46:46.000000000 +0100 @@ -6,7 +6,7 @@ package YAML::Tidy::Node; -our $VERSION = 'v0.8.0'; # VERSION +our $VERSION = 'v0.9.0'; # VERSION use overload '""' => \&_stringify; sub new($class, %args) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Run.pm new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Run.pm --- old/YAML-Tidy-v0.8.0/lib/YAML/Tidy/Run.pm 1970-01-01 01:00:00.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/lib/YAML/Tidy/Run.pm 2024-01-18 21:46:46.000000000 +0100 @@ -0,0 +1,166 @@ +# ABSTRACT: yamltidy runner +use strict; +use warnings; +use v5.20; +use experimental qw/ signatures /; +package YAML::Tidy::Run; + +our $VERSION = 'v0.9.0'; # VERSION + +use YAML::Tidy; +use YAML::Tidy::Config; +use YAML::LibYAML::API; +use Getopt::Long::Descriptive; +use Encode; + +my @options = ( + 'yamltidy %o file', + [ 'config-file|c=s' => 'Config file' ], + [ 'config-data|d=s' => 'Configuration as a string' ], + [ 'inplace|i' => 'Edit file inplace' ], + [ 'debug' => 'Debugging output' ], + [ 'partial' => 'Input is only a part of a YAML file' ], + [ 'indent=i' => 'Override indentation spaces from config' ], + [ 'batch|b' => 'Tidy all files - currently requires parameter "-" for filenames passed via STDIN' ], + [ 'verbose|v' => 'Output information' ], + [], + [ 'help|h', "print usage message and exit", { shortcircuit => 1 } ], + [ 'version', "Print version information", { shortcircuit => 1 } ], +); + +sub new($class, %args) { + my ($opt, $usage) = describe_options(@options); + my $cfg = YAML::Tidy::Config->new( + configfile => $opt->config_file, + configdata => $opt->config_data, + indentspaces => $opt->indent, + ); + my $yt = YAML::Tidy->new( + cfg => $cfg, + partial => $opt->partial, + ); + my $self = bless { + opt => $opt, + stdin => $args{stdin} || \*STDIN, + tidy => $yt, + usage => $usage, + }, $class; +} + +sub _output($self, $str) { + print $str; +} + +sub run($self) { + my $opt = $self->{opt}; + my $usage = $self->{usage}; + $self->_output($usage->text), return if $opt->help; + my @versions = ( + YAML::Tidy->VERSION, YAML::PP->VERSION, + YAML::LibYAML::API->VERSION, + YAML::LibYAML::API::XS::libyaml_version + ); + if ($opt->version) { + $self->_output(sprintf <<'EOM', @versions); + yamltidy: %s + YAML::PP: %s + YAML::LibYAML::API: %s + libyaml: %s +EOM + return; + } + + if ($opt->batch) { + my ($path) = @ARGV; + unless ($path eq '-') { + die "--batch currently requires '-' to receive filenames via STDIN\n"; + } + unless ($opt->inplace) { + die "--batch currently requires --inplace\n"; + } + my $in = $self->{stdin}; + while (my $file = <$in>) { + chomp $file; + $self->_process_file($file); + } + return; + } + my ($file) = @ARGV; + unless (defined $file) { + $self->_output($usage->text); + return; + } + + if ($file eq '-') { + $self->_process_stdin; + return; + } + + $self->_process_file($file); +} + +sub _process_file($self, $file) { + my $opt = $self->{opt}; + my $yt = $self->{tidy}; + my $changed = 0; + open my $fh, '<:encoding(UTF-8)', $file or die "Could not open '$file': $!"; + my $yaml = do { local $/; <$fh> }; + close $fh; + + $opt->debug and $self->_before($file, $yaml); + + my $out = $yt->tidy($yaml); + + if ($out ne $yaml) { + $changed = 1; + } + if ($opt->inplace) { + $changed and $self->_write_file($file, $out); + } + else { + $opt->debug or $self->_output(encode_utf8 $out); + } + $opt->debug and $self->_after($file, $out); + $self->_info(sprintf "Processed '%s' (%s)", $file, $changed ? 'changed' : 'unchanged'); +} + +sub _info($self, $msg) { + $self->{opt}->verbose and $self->_output("[info] $msg\n"); +} + +sub _write_file($self, $file, $out) { + open my $fh, '>:encoding(UTF-8)', $file or die "Could not open '$file' for writing: $!"; + print $fh $out; + close $fh; +} + +sub _process_stdin($self) { + my $opt = $self->{opt}; + my $yt = $self->{tidy}; + my $in = $self->{stdin}; + my $yaml = decode_utf8 do { local $/; <$in> }; + + $opt->debug and $self->_before('-', $yaml); + + my $out = $yt->tidy($yaml); + + if ($opt->debug) { + $self->_after('-', $out); + } + else { + $self->_output(encode_utf8 $out); + } +} + +sub _before($self, $file, $yaml) { + my $yt = $self->{tidy}; + $self->_output( "# Before: ($file)\n"); + $self->_output(encode_utf8 $yt->highlight($yaml)); +} + +sub _after($self, $file, $yaml) { + my $yt = $self->{tidy}; + $self->_output("# After: ($file)\n"); + $self->_output(encode_utf8 $yt->highlight($yaml)); +} +1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/lib/YAML/Tidy.pm new/YAML-Tidy-v0.9.0/lib/YAML/Tidy.pm --- old/YAML-Tidy-v0.8.0/lib/YAML/Tidy.pm 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/lib/YAML/Tidy.pm 2024-01-18 21:46:46.000000000 +0100 @@ -7,7 +7,7 @@ use experimental qw/ signatures /; package YAML::Tidy; -our $VERSION = 'v0.8.0'; # VERSION +our $VERSION = 'v0.9.0'; # VERSION use YAML::Tidy::Node; use YAML::Tidy::Config; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/lib/yamltidy.pod new/YAML-Tidy-v0.9.0/lib/yamltidy.pod --- old/YAML-Tidy-v0.8.0/lib/yamltidy.pod 1970-01-01 01:00:00.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/lib/yamltidy.pod 2024-01-18 21:46:46.000000000 +0100 @@ -0,0 +1,115 @@ +=head1 NAME + +yamltidy - Reformat YAML files + +=head1 ABSTRACT + + + +=head1 DESCRIPTION + +This script checks YAML files according to a configuration and automatically +reformats them. +It will output the formatted code on standard output, or edit the file +directly. + + +=head1 EXAMPLES + +=over + +=item Tidy a file and print to stdout + + % cat in.yaml + --- + a: + b: + c: d + % yamltidy in.yaml + --- + a: + b: + c: d + +=item Tidy content from stdin + + % echo '--- + a: + b: + c: d' | yamltidy - + --- + a: + b: + c: d + + +=item Tidy a file and save the result back + + % yamltidy --inplace in.yaml + % cat in.yaml + --- + a: + b: + c: d + +=item Process a list of files from stdin + + # Tidy all .yaml files that are in git + % git ls-files | grep '.yaml$' | yamltidy --inplace --batch - + # short options + % git ls-files | grep '.yaml$' | yamltidy -i -b - + # Only tidy modified files + % git ls-files --modified | grep '.yaml$' | yamltidy --inplace --batch - + +In the future yamltidy can take a directory as an argument and process +file name patterns from configuration. + +=item Use a certain configuration file + + % yamltidy -c /path/to/yamltidy.yaml file.yaml + +=item Partial formatting + +From within an editor you can pass only a part of the file on stdin. +This is important for keeping the indentation of that part. Also +it won't add a C<---> header. Compare: + + % echo ' + a: + b: c' | yamltidy - + --- + a: + b: c + % echo ' + a: + b: c' | yamltidy --partial - + + a: + b: c + +Vim example configuration: + + # :noremap <leader>yt :%!yamltidy -<CR> + # :vnoremap <leader>yt :!yamltidy --partial -<CR> + +=back + + +=head2 GLOBAL OPTIONS + + --config-file -c Config file + --config-data -d Configuration as a string + --inplace -i Edit file inplace (flag) + --debug Debugging output (flag) + --partial Input is only a part of a YAML file (flag) + --indent Override indentation spaces from config + --batch -b Tidy all files - currently requires parameter "-" for filenames passed via STDIN (flag) + --verbose Output information (flag) + --help -h print usage message and exit (flag) + --version Print version information (flag) + + +=head2 SUBCOMMANDS + + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/t/00.compile.t new/YAML-Tidy-v0.9.0/t/00.compile.t --- old/YAML-Tidy-v0.8.0/t/00.compile.t 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/t/00.compile.t 2024-01-18 21:46:46.000000000 +0100 @@ -6,12 +6,13 @@ use Test::More; -plan tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0); +plan tests => 5 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'YAML/Tidy.pm', 'YAML/Tidy/Config.pm', - 'YAML/Tidy/Node.pm' + 'YAML/Tidy/Node.pm', + 'YAML/Tidy/Run.pm' ); my @scripts = ( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/t/02.run.t new/YAML-Tidy-v0.9.0/t/02.run.t --- old/YAML-Tidy-v0.8.0/t/02.run.t 1970-01-01 01:00:00.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/t/02.run.t 2024-01-18 21:46:45.000000000 +0100 @@ -0,0 +1,128 @@ +#!/usr/bin/perl +use warnings; +use v5.20; +use Test::More; +use Test::Warnings qw/ :report_warnings /; +use Encode; +use experimental qw/ signatures /; + +use FindBin '$Bin'; +use YAML::Tidy::Run; + +my (@out, @before, @after, %write); +no strict 'refs'; +no warnings 'redefine'; +local *{"YAML::Tidy::Run::_output"} = sub($, $msg) { push @out, $msg }; +local *{"YAML::Tidy::Run::_before"} = sub($, $file, $yaml) { push @before, $yaml }; +local *{"YAML::Tidy::Run::_after"} = sub($, $file, $yaml) { push @after, $yaml }; +local *{"YAML::Tidy::Run::_write_file"} = sub($, $file, $out) { $write{$file} = $out }; + +my $data_start = tell *DATA; + +sub clean { + seek DATA, $data_start, 0; + @out = (); @before = (); @after = (); %write = (); +} + +my $infile = "$Bin/data/run.yaml"; +my $data = do { local $/; <DATA> }; +open my $fh, '<', $infile or die $!; +my $input = do { local $/; <$fh> }; +close $fh; + +clean(); + +my $ytr; +my $tidied = <<'EOM'; +--- +some: input file +that: {should be: tidied} +EOM +my $filelist = <<'EOM'; +a/b/1.yaml +c/d/2.yaml +EOM + +subtest stdin => sub { + local @ARGV = qw/ - /; + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + is $out[0], $tidied, 'Tidied stdin'; + clean(); + + local @ARGV = qw/ - --debug /; + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + is $before[0], $data, 'debug before'; + is $after[0], $tidied, 'debug after'; + clean(); +}; + +subtest information => sub { + local @ARGV = qw/ --version /; + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + like $out[0], qr{yamltidy: .*YAML::PP: .*}s, '--version'; + clean(); + + local @ARGV = qw/ --help /; + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + like $out[0], qr{yamltidy.*options}s, '--help'; + clean(); +}; + +subtest file => sub { + local @ARGV = $infile; + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + is $out[0], $tidied, 'Tidied file'; + clean(); + + local @ARGV = (qw/ --debug /, $infile); + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + is $before[0], $input, 'debug before'; + is $after[0], $tidied, 'debug after'; + clean(); + + local @ARGV = (qw/ --inplace /, $infile); + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + ok exists $write{ $infile }, 'inplace - file written'; + is $write{ $infile }, $tidied, 'inplace - file content correct'; + clean(); + + local @ARGV = (qw/ --inplace --verbose /, $infile); + $ytr = YAML::Tidy::Run->new(stdin => \*DATA); + $ytr->run; + like $out[0], qr{info.*Processed.*run.yaml.*\bchanged}, 'Verbose output'; + clean(); +}; + +subtest 'batch stdin' => sub { + my @f; + local *{"YAML::Tidy::Run::_process_file"} = sub($, $file) { push @f, $file }; + open my $in, '<', \$filelist; + local @ARGV = (qw/ -b - --inplace /); + $ytr = YAML::Tidy::Run->new(stdin => $in); + $ytr->run; + is $f[0], 'a/b/1.yaml', 'file 1'; + is $f[1], 'c/d/2.yaml', 'file 2'; + clean(); + + local @ARGV = (qw/ --batch - /); + $ytr = YAML::Tidy::Run->new(stdin => $in); + eval { + $ytr->run; + }; + my $err = $@; + like $err, qr/--batch currently requires --inplace/, '--inplace required'; + clean(); +}; + +done_testing; + +__DATA__ +"some": input file +that: {"should be":tidied} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/t/data/run.yaml new/YAML-Tidy-v0.9.0/t/data/run.yaml --- old/YAML-Tidy-v0.8.0/t/data/run.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/t/data/run.yaml 2024-01-18 21:46:46.000000000 +0100 @@ -0,0 +1,2 @@ +"some": input file +that: {"should be":tidied} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/YAML-Tidy-v0.8.0/xt/03.spelling.t new/YAML-Tidy-v0.9.0/xt/03.spelling.t --- old/YAML-Tidy-v0.8.0/xt/03.spelling.t 2024-01-05 22:40:27.000000000 +0100 +++ new/YAML-Tidy-v0.9.0/xt/03.spelling.t 2024-01-18 21:46:46.000000000 +0100 @@ -12,6 +12,8 @@ __DATA__ linter perltidy +reformats +SUBCOMMANDS yamllint yamltidy Müller