Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erdnaxeli/clip
Deserialize CLI parameters to an object, with errors and help management.
https://github.com/erdnaxeli/clip
cli crystal crystal-lang
Last synced: 4 days ago
JSON representation
Deserialize CLI parameters to an object, with errors and help management.
- Host: GitHub
- URL: https://github.com/erdnaxeli/clip
- Owner: erdnaxeli
- License: mit
- Created: 2021-03-20T18:57:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-04-11T20:32:30.000Z (over 3 years ago)
- Last Synced: 2024-11-02T13:33:56.921Z (11 days ago)
- Topics: cli, crystal, crystal-lang
- Language: Crystal
- Homepage: https://erdnaxeli.github.io/clip/
- Size: 470 KB
- Stars: 18
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# Clip
Clip (CLI Parser) allows you to deserialize CLI parameters into an object, and
generates the help for you.The goal of Clip is to let you in control.
It does not execute your code.
It does not print anything.
It can read from ARGV but also from any array of strings.
You choose what you want to do.**Documentation**:
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
clip:
github: erdnaxeli/clip
```2. Run `shards install`
## Usage
In a file command.cr:
```crystal
require "clip"@[Clip::Doc("An example commmand.")]
struct Command
include Clip::Mapper@[Clip::Doc("Enable some effect.")]
getter effect = false@[Clip::Doc("The file to work on.")]
getter file : String
endbegin
command = Command.parse
rescue ex : Clip::ParsingError
puts ex
exit
endcase command
when Clip::Mapper::Help
puts command.help
else
if command.effect
puts "Doing something with an effect on #{command.file}."
else
puts "Doing something on #{command.file}."
end
end
```Then:
```Shell
$ crystal build command.cr
$ ./command
Error:
argument is required: FILE
$ ./command --help
Usage: ./command [OPTIONS] FILEAn example commmand.
Arguments:
FILE The file to work on. [required]Options:
--effect / --no-effect Enable some effect. [default: false]
--help Show this message and exit.
$ ./command myfile
Doing something on myfile.
$ ./command --effect myfile
Doing something with an effect on myfile.
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Alexandre Morignot](https://github.com/erdnaxeli) - creator and maintainer