dustbyte / klash Goto Github PK
View Code? Open in Web Editor NEWNew paradigm for argument parsing in Go
License: MIT License
New paradigm for argument parsing in Go
License: MIT License
In order to facilitate custom type handling within a klashed structure, implement a check on a specific interface and if that type responds to this interface, then extract its converted value by calling the method of the interface.
The interface will be of the form:
type Convertible interface {
FromString(stringval string) error
}
And the type implementing this Method should fill itself based on the string value.
Note: If a structure is provided and implements this interface, it is no longer considered as a subcommand, see #5
Allow via tags to make an argument depending on another one. The dependency is not mutual.
Tag spec: klash-group:"arg1,arg2"
The field name cases are not important.
Allow an argument to be marked as required via Tag.
Tag spec: klash-required:"true"
Standard klash tags have very long names, which can be unconvenient when reading code.
Provide shortcuts over tags to allow more consive parameter tweaking with klash.
Handle exclusion via tags. The exclusion is not mutual.
Tag spec: klash-exclude:"arg1,arg2..."
The field name cases are not important.
If a structure type field responding to a defined interface is present within the arguments structure, this field is therefore considered as an "automatic" subcommand (compared to manual that plays with the stop behavior).
When encountered and if matching the program's arguments, the interface's function is executed when argument parsing is finised and the leftovers are parsed against this structure, and so on recursively (that is, a first level subcommand is not executed when one of its fields also responds this interface).
The substructure must respond the following interface:
type Command interface {
Launch(parameters interface{}, leftover []string)
}
parameters
hold a pointer to the root parameters structure.leftover
holds a list of remaining positional argumentsAllow via tags to provide an aliased name for the argument.
Tag spec: klash-alias:"othername"
Make klash handle automatically help and print usage on error or when the -h/--help option is provided and non-positional parsing is not stopped
Provide a way to add an help message to fields via tags
Tag spec: klash-help:"Help message"
Allow to mark arguments to be marked as positional.
In this case, the order of declaration of fields in the structure is significant and leftovers produce and error.
Another rule is that only the last positional field can be of slice type, in this case it stores every positional argument provided.
Tag spec: klash-positional:"true"
For the moment, only non-positional arguments followed by another argument are taken into account. Provide the --argument=value behavior.
Allow to use multiple single-char arguments when all the arguments are booleans.
For example:
./main -vd
wil handle -v/--verbose and -d/--debug
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.