From 9af77367fc77b33b2a937515098eb52d0b4bb5d2 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 1 Jun 2024 01:37:33 +0200 Subject: [PATCH 1/1] tools/mkjson: set commandline flags as get options Support debugging overrides such as keyboard/altgr/weur.eng.inc.pl ?map. --- tools/mkjson | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/mkjson b/tools/mkjson index dace34a..3b1bfa9 100755 --- a/tools/mkjson +++ b/tools/mkjson @@ -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] \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; -- 2.30.2