soveran / clap Goto Github PK
View Code? Open in Web Editor NEWCommand line argument parsing
License: MIT License
Command line argument parsing
License: MIT License
Instead of just accepting lambdas, CLAP could be made more flexible by accepting any object that has a #call method. Basically replace:
arity = [flag.arity, 0].max
with:
flag = flag.method(:call) unless Proc === flag
arity = [flag.arity, 0].max
How to do option aliases?
CLAP.run ARGV,
'-o' => lambda { ... }
'--output' => lambda { ... }
Where both lambdas are the same is redundant. Of course we could create a variable for it:
output_opt = lambda { ... }
CLAP.run ARGV,
'-o' => output_opt
'--output' => output_opt
But perhaps an option array could be supported?
CLAP.run ARGV,
['-o', '--output'] => lambda { ... }
Also, I wonder if the option itself could be a regular expression?
CLAP.run ARGV,
/=/ => lambda { |opt| k, v = opt.split('='); options[k] = v }
I really love the simplicity of this library, btw, so maybe these ideas are not useful enough to warrant the additional complexity. But I figure they are worth some thought.
I'm wondering how Clap might be extended to support standardized command line help output:
Clap.help "Usage: #{$0} [options]",
"-a" => "explain a"
"-b" => "explain b"
Clap.run ARGV,
"-a" => lambda { |param| ... },
"-b" => lambda { ... }
"-h" => Clap.help
?
@soveran Could Clap provide subcommand support like the features in git.
For example:
if I do git add
, it will print out help message
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Then I can do git add some_files
to add files
To support this feature, maybe clap should support various number of arguments for each flag?
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.