tools/mkjson: set commandline flags as get options
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 31 May 2024 23:37:33 +0000 (01:37 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 3 Jul 2024 22:40:25 +0000 (00:40 +0200)
Support debugging overrides such as keyboard/altgr/weur.eng.inc.pl ?map.

tools/mkjson

index dace34afce91d2f6ca610c2d82b10bd6d039f65b..3b1bfa9317cce5f17308fb44cc733fa7e26adb91 100755 (executable)
@@ -1,13 +1,22 @@
 #!/usr/bin/env perl
 use 5.012;
 use warnings;
-use JSON;
 use re '/msx';
+use JSON;
+
+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] <input>\n";
 
-my %opt;
 my $jsonify = JSON->new->utf8->canonical;
-$jsonify->pretty if $opt{pretty};
+$jsonify->pretty if $get{pretty};
 
-my $data = do "./$ARGV[0]" or die $@;
+my $data = do "./$file" or die $@;
 print $jsonify->encode($data)
        =~ s{\[ \K\n ([^][]+) (?=\])}{$1 =~ s/(?:\A|\n) \s*//gr}reg;