index: release v1.18 with only altgr index linked
[sheet.git] / tools / mkclioptions
1 #!/usr/bin/env perl
2 use 5.014;
3 use warnings;
4 use utf8;
5 use re '/msx';
6 use open OUT => ':encoding(utf-8)', ':std';
7
8 our $VERSION = '1.00';
9
10 my %group = (
11         core => [qw(
12                 cat chgrp chmod chown cp date df ln ls mkdir mknod mktemp mv
13                 readlink rm rmdir touch uname
14         )],
15         usr => [qw(
16                 base64 basename chcon cksum comm csplit cut dircolors
17                 dirname du env expand expr factor fmt fold groups head hostid id
18                 install join link logname md5sum mkfifo nice nl nohup nproc numfmt od
19                 paste pathchk pinky pr printenv printf ptx realpath runcon seq sha1sum
20                 shred shuf sort split stat
21                 stdbuf sum tac tail tee test timeout tr truncate tsort tty unexpand
22                 uniq unlink users wc who whoami yes
23         )],
24         -usr => [qw(
25                 base32 b2sum sha224sum sha256sum sha384sum sha512sum
26         )],
27         bsd => [qw(
28                 calendar col column hexdump look ncal
29         )],
30         more => [qw(
31                 find xargs  free skill htop uptime watch  sed awk perl figlet less
32                 curl wget ping fping ssh nc
33         )],
34         corerest => [qw(
35                 dd pwd sleep stty sync
36         )],
37         git => [map {"git $_"} qw( log status )],
38 );
39
40 say '# automatically generated by tools/mkclioptions';
41 say '+{';
42
43 for my $program (map { $group{$_} ? @{$group{$_}} : $_ } @ARGV) {
44         my $help = eval {
45                 local $/;
46                 open my $output, '-|', split(/\h/, $program), '--help';
47                 warn "$program exited with status $?\n" if $?;
48                 return readline $output;
49         } or next;
50
51         printf "'%s' => {\n", $program;
52
53         while ($help =~ m{ ^\h+ (-\N*?) (?: \h{3,} (\N*) )? \n }g) {
54                 #TODO: continuations
55                 my ($options, $explain) = ($1, $2);
56                 $explain =~ s/_\010//g if defined $explain;  # underlines in less
57                 my ($short) = $options =~ m{ (?<! \H) -([^-]) (?! \w) }
58                         or 0 or next;  #TODO: option to keep long
59                 printf "  '%s' => [q{%s}, q{%s}],\n", $short // '', $options, $explain // '';
60         }
61
62         say '},';
63 }
64
65 say '}';
66
67 __END__
68
69 =head1 NAME
70
71 mkclioptions
72
73 =head1 SYNOPSIS
74
75     mkclioptions ls >clioptions.inc.pl
76
77 =head1 AUTHOR
78
79 Mischa POSLAWSKY <perl@shiar.org>
80
81 =head1 LICENSE
82
83 Licensed under the GNU Affero General Public License version 3.
84