Top 1.7% dependent packages on proxy.golang.org
Top 1.2% dependent repos on proxy.golang.org
Top 7.8% forks on proxy.golang.org
Top 1.5% docker downloads on proxy.golang.org
proxy.golang.org : github.com/zeebo/clingy
Package clingy is a library to create command line interfaces. The API is a design experiment that prioritizes discoverability of the code that uses it over anything else. There are two main ways that this can be seen. First, commands are defined in the same call that is used to execute them. In this way, you cannot define the tree of commands in a bunch of different files in the package, mutating state during init() functions, or otherwise. For example, consider the following execution: Because all of the commands are defined in that single spot, we know exactly which commands are available and where they are defined. Secondly, flags and arguments for commands are defined at the time they are loaded, and happen as part of a method call on the command implementation itself. This provides incentives to store the state on the command object itself. For example: This causes the command implementation to be more discoverable because you have a single location that contains all of the state the command will inspect. This also aids in unit testing, because you can construct values directly and execute them, skipping the Setup step and avoiding having to make mocks or fakes to inject the parameters. In service of this goal, some tradeoffs are made. Most notably, the return type for arguments and flags is `interface{}` and type casts are required. This was found to be acceptable because in typical usage, the argument will be directly assigned into a typed struct field, so the compiler complains if an incorrect type assertion is used. This changes a dynamic failure to a minor redundancy. Additionally, the code with the type assertions is executed right away whenever a command is run, so any testing will surface any bugs. Enjoy!
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/zeebo/clingy
License: CC0-1.0
Latest release: over 1 year ago
First release: over 2 years ago
Namespace: github.com/zeebo
Dependent packages: 10
Dependent repositories: 20
Stars: 8 on GitHub
Forks: 6 on GitHub
Docker dependents: 4
Docker downloads: 274
See more repository details: repos.ecosyste.ms
Last synced: about 2 months ago