From: Mischa POSLAWSKY Date: Fri, 6 Sep 2019 18:57:42 +0000 (+0200) Subject: cli: mkclioptions tool to parse help output of given commands X-Git-Tag: v1.12~27 X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/65faae1c253e37cb659e16966c18a07ca2822bd7 cli: mkclioptions tool to parse help output of given commands Initial automation of getting available options from basic GNU programs. --- diff --git a/tools/mkclioptions b/tools/mkclioptions new file mode 100755 index 0000000..54192b0 --- /dev/null +++ b/tools/mkclioptions @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use 5.014; +use warnings; +use utf8; +use re '/msx'; +use open OUT => ':utf8', ':std'; + +our $VERSION = '1.00'; + +say '# automatically generated by tools/mkclioptions'; +say '+{'; + +for my $program (@ARGV) { + my $help = eval { + local $/; + open my $output, '-|', $program, '--help'; + 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); + my ($short) = $options =~ m{ (?clioptions.inc.pl + +=head1 AUTHOR + +Mischa POSLAWSKY + +=head1 LICENSE + +Licensed under the GNU Affero General Public License version 3. +