cli: mkclioptions core program presets
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 6 Sep 2019 18:57:42 +0000 (20:57 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 1 Mar 2022 20:02:26 +0000 (21:02 +0100)
Input group names for selected entries from debian coreutils, bsdmainutils,
git subcommands, others.

tools/mkclioptions

index 74cdcf61369c5f101a720953aa4344a8edeb9b3a..020f0250afcd3c651472b7913813d48481e7f3fc 100755 (executable)
@@ -7,24 +7,56 @@ use open OUT => ':encoding(utf-8)', ':std';
 
 our $VERSION = '1.00';
 
 
 our $VERSION = '1.00';
 
+my %group = (
+       core => [qw(
+               cat chgrp chmod chown cp date df ln ls mkdir mknod mktemp mv
+               readlink rm rmdir touch uname
+       )],
+       usr => [qw(
+               base64 basename chcon cksum comm csplit cut dircolors
+               dirname du env expand expr factor fmt fold groups head hostid id
+               install join link logname md5sum mkfifo nice nl nohup nproc numfmt od
+               paste pathchk pinky pr printenv printf ptx realpath runcon seq sha1sum
+               shred shuf sort split stat
+               stdbuf sum tac tail tee test timeout tr truncate tsort tty unexpand
+               uniq unlink users wc who whoami yes
+       )],
+       -usr => [qw(
+               base32 b2sum sha224sum sha256sum sha384sum sha512sum
+       )],
+       bsd => [qw(
+               calendar col column hexdump look ncal
+       )],
+       more => [qw(
+               find xargs  free skill htop uptime watch  sed awk perl figlet less
+               curl wget ping fping ssh nc
+       )],
+       corerest => [qw(
+               dd pwd sleep stty sync
+       )],
+       git => [map {"git $_"} qw( log status )],
+);
+
 say '# automatically generated by tools/mkclioptions';
 say '+{';
 
 say '# automatically generated by tools/mkclioptions';
 say '+{';
 
-for my $program (@ARGV) {
+for my $program (map { $group{$_} ? @{$group{$_}} : $_ } @ARGV) {
        my $help = eval {
                local $/;
        my $help = eval {
                local $/;
-               open my $output, '-|', $program, '--help';
+               open my $output, '-|', split(/\h/, $program), '--help';
+               warn "$program exited with status $?\n" if $?;
                return readline $output;
        } or next;
 
                return readline $output;
        } or next;
 
-       printf "%s => {\n", $program;
+       printf "'%s' => {\n", $program;
 
        while ($help =~ m{ ^\h+ (-\N*?) (?: \h{3,} (\N*) )? \n }g) {
                #TODO: continuations
                my ($options, $explain) = ($1, $2);
 
        while ($help =~ m{ ^\h+ (-\N*?) (?: \h{3,} (\N*) )? \n }g) {
                #TODO: continuations
                my ($options, $explain) = ($1, $2);
-               my ($short) = $options =~ m{ (?<! \H) -([^-]) (?! [^,\h]) }
-                       or next;
-               printf "  ['%s', '%s', q{%s}]\n", $short, $options, $explain // '';
+               $explain =~ s/_\010//g if defined $explain;  # underlines in less
+               my ($short) = $options =~ m{ (?<! \H) -([^-]) (?! \w) }
+                       or 0 or next;  #TODO: option to keep long
+               printf "  '%s' => [q{%s}, q{%s}],\n", $short // '', $options, $explain // '';
        }
 
        say '},';
        }
 
        say '},';