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 '+{';
-for my $program (@ARGV) {
+for my $program (map { $group{$_} ? @{$group{$_}} : $_ } @ARGV) {
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;
- 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);
- 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 '},';