X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/e6b10645e7470208f5122055489c7a19733e50bc..20883523f524360de2c7758b02d15be980ed08c3:/tools/mkjson diff --git a/tools/mkjson b/tools/mkjson index 6a7d948..3b1bfa9 100755 --- a/tools/mkjson +++ b/tools/mkjson @@ -1,7 +1,22 @@ #!/usr/bin/env perl use 5.012; use warnings; +use re '/msx'; use JSON; -my $data = do "./$ARGV[0]" or die $@; -print JSON->new->utf8->canonical->encode($data); +our $VERSION = '1.00'; + +our %get; +while (@ARGV) { + $ARGV[0] =~ s/^--// or last; # --flag + my ($name, $val) = split /=/, shift, 2 or last; # set until empty + $get{$name} = $val // 1; +} +my $file = shift or die "Usage: $0 [--options] \n"; + +my $jsonify = JSON->new->utf8->canonical; +$jsonify->pretty if $get{pretty}; + +my $data = do "./$file" or die $@; +print $jsonify->encode($data) + =~ s{\[ \K\n ([^][]+) (?=\])}{$1 =~ s/(?:\A|\n) \s*//gr}reg;