https://github.com/cosmictoast/janet-kargs
Keyword argument parsing for Janet.
https://github.com/cosmictoast/janet-kargs
Last synced: 4 months ago
JSON representation
Keyword argument parsing for Janet.
- Host: GitHub
- URL: https://github.com/cosmictoast/janet-kargs
- Owner: CosmicToast
- License: unlicense
- Created: 2023-04-09T00:57:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-09T01:16:38.000Z (about 3 years ago)
- Last Synced: 2025-03-21T19:59:20.639Z (about 1 year ago)
- Language: Janet
- Size: 1.95 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Janet Keyword Args (KArgs)
Kargs aim to make cli arguments function like Janet arguments.
This follows a few simple rules.
1. If we're not expecting a value, we try to parse a flag.
2. A flag is defined as either a short flag or a long flag.
A short flag can be `-a` or `-abcd` (this becomes an `:abcd` keyword, for use as flags).
A long flag can be `--abcd=value` (where value is parsed as in 3)
or `--abcd` (in which case the value is expected to be the next argument).
3. If a flag is matched, flag semantics (as above) take over.
Otherwise, or if we expect a value, we parse it using the Janet parser.
If the parser outputs a symbol or fails to parse the value, we turn it into an as-is string.
And that's it.
Have fun!
Note that this library is not stable, I reserve the right to change it whenever until 1.0.0 is tagged.
This is because I'm going to pull a hehecat and use it in production to see if it feels right or not.
## Bugs
Technically, I use `parse` and not `parse-all`.
I probably should use `parse-all` and also check for `length`.
I don't care though.
Test condition: "1 hi" should result in "1 hi" but results in 1.