reeflective / flags Goto Github PK
View Code? Open in Web Editor NEWGenerate cobra command trees from structs. Go-flags compliant tags. Advanced CLI functionality, out-of-the-box.
License: BSD 3-Clause "New" or "Revised" License
Generate cobra command trees from structs. Go-flags compliant tags. Advanced CLI functionality, out-of-the-box.
License: BSD 3-Clause "New" or "Revised" License
Currently, the code parsing the positional argument words (strings) onto their type is directly taken from
the old go-flags code. While not working badly, the range of types supported is largely inferior to the range
of types supported for flags.
This is not really hard, and should not represent a huge workload.
I just realized this would be better toward the end of my work.
flags.Value
type for generating positional arguments slots and parsing words onto them.Currently there are two cases in which the command scan should return an error and does not:
Other than that, there is still some edge cases for positional parsing.
Most cases work fine, and are covered by tests.
Currently, tagged completion directives have precedence over any completer interface implemented by the type being tagged (as flag or positional). Using a complete:"+CompleterName"
should enable stacking both the tagged directive and the type completer
For as long as this library exists the *Command
and the Group
type have had partially overlapping roles,
since *Command
embeds a *Group
for storing its struct data and various other attributes, but this has
introduced a little flaw that Cobra has avoided: purely arbitrary declaration/parsing/lookup of subcommands/groups/options.
Below is an attempt at explaining this issue, what lacks and what causes (please blame me for my lack of clarity):
Grouping commands
Namespaced options
*Group
type is concerned with options, there are absolutely no complaints to be made. Everything-P
accepting a single-rune argument, like -Pn
-nmap's users hello- and yet anothern
switch, such as port list).-P
-as in nmap's case- has many different suboption switches, which you want to give a bit of structure.To speak of implementation details briefly: binding a command will scan the corresponding struct for both subcommands
and option groups (arbitrarily nested), while binding a group of options will only scan for namespaced option groups (childs).
Parser
(or command).description:"bla"
, optional:"yes"
, etc. However such a change will apply to new tags such as group:"name"
, where the groupWhen an option Path
has both -p/--path
flags, when having inserted -p
and hitting TAB will not either space it (accepting this short option, not colliding with any other than its long-name alias. This should be harmonized, probably through zstyle instructions given with above any group (like if no other match than your own alias, you're good to go)
Many fields of the cobra's Command
type have been merged into our own command type. Most of them are not used at the moment, while they should. Verify and use them accordingly.
Unless the option specificaly requires an = sign between it's name and its arguments, remove it from help usage. Probably will cross with how this sign is handled in the completions, depending on the option's requirements and stuff
Currently the "Help Options" category, which contains only a -h/--help flag, should be removed from the default usage printing
In option.go
's last method isValidValue()
, we should wrap the error returned by the implemented ValueValidator
of the option.
The parsingState
object should be passed from command to subcommand (each time one is found), so that parsing can be operated similarly to Cobra. \n This does not change the fact that a Client
type is still needed for parsing a command line.
Some tests should be added to the library:
flags.Value
interface), that areKong (and probably other libraries) do not require developers to encapsulate their positional arguments into a specific struct
. This has the advantage of being simpler when the positional structure is not sophisticated. In addition, people are probably used to this.
Currently, completion directives that used through struct tags are restricted to a few ones.
Two sorts of enhancements could be thought of:
carapace
engine.carapace-bin
repository declares litteraly hundreds of system completers,The function parseState.addArg(arg)
stores significant errors into itself, but returns an error nonethless, which is not uniformly checked/handled across the codebase. The situation has been slightly enhanced, but probably not optimal yet.
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.