Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skellock/crappycli
A crappy nim package for parsing command line arguments. 💩
https://github.com/skellock/crappycli
cli command-line nim
Last synced: about 2 months ago
JSON representation
A crappy nim package for parsing command line arguments. 💩
- Host: GitHub
- URL: https://github.com/skellock/crappycli
- Owner: skellock
- License: mit
- Created: 2018-06-24T01:23:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-28T16:40:49.000Z (over 6 years ago)
- Last Synced: 2024-10-03T12:44:50.011Z (4 months ago)
- Topics: cli, command-line, nim
- Language: Nim
- Size: 18.6 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crappycli 💩
[![CircleCI](https://circleci.com/gh/skellock/crappycli.svg?style=svg)](https://circleci.com/gh/skellock/crappycli)
A crappy [`nim`](https://nim-lang.org) package for parsing command line arguments.
### Warning
I'm new at `nim` and am extracting this from one of my projects to get used to writing packages.
You probably want to use one of the many other CLI argument parsing packages instead. 😃
# Installing
`nimble install https://github.com/skellock/crappycli`
Or, hey, just copy the `crappycli.nim` file and paste it into your project. 💃
# Usage
```nim
import crappycli# new crappy cli!
let cli = newCrappyCli()# check for a switch that's just a flag
cli.has("force")# read a switch that has a value
cli["output"]# read a switch as an int with a fallback
cli.intValue("l", 100)# read a switch as a string with a fallback
cli.stringValue("p", "party")# read positional arguments
cli.first
cli.second
cli.third
cli.last
cli.nth(1) # reads the 1st positional argument (1-based 🤓)# count some stuff
cli.switchCount
cli.positionalCount
cli.empty
```### Ambiguous Switches
Sometimes your switches will be flags; meaning, they don't have a value associated with them.
By default, switches consume the next word after them... so, if you want to keep those as positional arguments, then you've gotta tell `CrappyCli` about your flags up front.
Look, I told ya it was crappy! 🎰
```nim
# alternate way to create it by telling it switches
# which have no values
let cli = commandLineParams.newCrappyCli(
flags = @["verbose"]
)# ^ used for corner cases where you have positionals
# right after switches, for example:
#
# mycli -v filename.json
#
# ^ in this case, we want the `-v` to be a flag and
# the `filename.json` to be a positional.
```### DIY commandLineParams
By default, `CrappyCli` tries to read from `commandLineParams` from `os`. You can override this:
```nim
let cli = commandLineParams.newCrappyCli(
params = @["omg", "custom", "-v"]
)
```# License
MIT. 🤷
# Contributing
😂
If you have any tips, I'm all ears!