#!/usr/bin/env perl use 5.014; use warnings; use utf8; use re '/msx'; use open OUT => ':encoding(utf-8)', ':std'; 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 (map { $group{$_} ? @{$group{$_}} : $_ } @ARGV) { my $help = eval { local $/; open my $output, '-|', split(/\h/, $program), '--help'; warn "$program exited with status $?\n" if $?; return readline $output; } or next; printf "'%s' => {\n", $program; while ($help =~ m{ ^\h+ (-\N*?) (?: \h{3,} (\N*) )? \n }g) { #TODO: continuations my ($options, $explain) = ($1, $2); $explain =~ s/_\010//g if defined $explain; # underlines in less my ($short) = $options =~ m{ (? [q{%s}, q{%s}],\n", $short // '', $options, $explain // ''; } say '},'; } say '}'; __END__ =head1 NAME mkclioptions =head1 SYNOPSIS mkclioptions ls >clioptions.inc.pl =head1 AUTHOR Mischa POSLAWSKY =head1 LICENSE Licensed under the GNU Affero General Public License version 3.