sago35 / getopt-kingpin Goto Github PK
View Code? Open in Web Editor NEWperl command line and flag parser (like golang kingpin)
License: Other
perl command line and flag parser (like golang kingpin)
License: Other
Normally, human-readable command output is newline-terminated. Kingpin's error messages are not. Popular shells don't take it very well: bash
shows its prompt after the non-terminated line, and zsh (version 5.4.2 in Nixos) somehow "eats" the non-terminated line, thus hiding the error message completely.
Hi,
excellent work...
Any ideas about automatic support for shell completion?
Thanks,
For arguments like this:
myscript.pl command --define os=linux --define arch=amd64
And $flag->values
should return:
{
"os" => "linux",
"arch" => "amb64",
}
Getopt::Long supports this. If you think this would be a useful feature, I would be happy to send you a patch.
Instead of scalar.
In japanese windows, file paths encoding is cp932.
When you want to use file with default value,
current : sort {$a->name ne "help" || $a->name cmp $b->name} $self->flags->values
call die instead of croak.
$kingpin->parse
parses @ARGV
but $kingpin->parse(@args)
parses @args
... except if @args
is an empty array, in which case it parses @ARGV
even though that's not what you asked it to do.
If parse
took an arrayref, then it would be easier for parse
to tell if you wanted it to parse your array or parse @ARGV
.
$kingpin->parse( \@args ); # parse @args
$kingpin->parse( [] ); # parse an empty array
$kingpin->parse; # parse @ARGV
But Getopt::Kingpin has already existed for four years, so it is probably too late to change the behaviour of parse
. Instead I think a separate method called parse_array
should be added and parse
should be... not quite deprecated but discouraged.
This is kingpin's README.md.
The place-holder value for a flag is the value used in the help to describe
the value of a non-boolean flag.
The value provided to PlaceHolder() is used if provided, then the value
provided by Default() if provided, then finally the capitalised flag name is
used.
Here are some examples of flags with various permutations:
--name=NAME // Flag(...).String()
--name="Harry" // Flag(...).Default("Harry").String()
--name=FULL-NAME // flag(...).PlaceHolder("FULL-NAME").Default("Harry").String()
For example, sometimes we want to hide a flag that is only used for debug.
For me, it would be useful if Getopt::Kingpin supported "lazy" defaults like Moo/Moose attributes do. So, for example:
$command->flag("email", "Email address")->default(sub { ... })->string;
Looking up the email address might be an expensive operation; it might need a database lookup for example. The coderef would only be called if the user does not provide --email=something
on the command line.
It would allow things like:
$command->flag("email", "Email address")->default(sub {
print STDERR "Please provide an email address!\n";
chomp( my $email = <STDIN> );
return $email;
})->string;
I can provide a PR if you think this is a useful feature which you would be likely to accept.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.