Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ariary/quicli
🪆 Go library to quickly build CLI using a simple one-liner
https://github.com/ariary/quicli
cli flags golang-library helper oneliner
Last synced: 14 days ago
JSON representation
🪆 Go library to quickly build CLI using a simple one-liner
- Host: GitHub
- URL: https://github.com/ariary/quicli
- Owner: ariary
- License: unlicense
- Created: 2022-07-30T11:19:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-27T06:27:30.000Z (about 1 year ago)
- Last Synced: 2024-11-11T03:36:25.363Z (2 months ago)
- Topics: cli, flags, golang-library, helper, oneliner
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 🏃⌨️ quicli
### Build CLI in one line
..or two```golang
cli := quicli.Cli{Usage:"SayToTheWorld [flags]",Description: "Say Hello... or not. If you want to make the world aware of it you also could",Flags: quicli.Flags{{Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},{Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},{Name: "world", Description: "announce it to the world"},},}
cfg := cli.Parse()
```With this code you obtain the following help message:
```
Say Hello... or not. If you want to make the world aware of it you also couldUsage: SayToTheWorld [flags]
--count -c how many times I want to say it. Sometimes repetition is the key. (default: 1)
--say -s say something. If you are polite start with a greeting. (default: "hello")
--world -w announce it to the world. (default: false)Use "./sayhello --help" for more information about the command.
```Pretty indented version
```golang
cli := quicli.Cli{
Usage: "SayToTheWorld [flags]",
Description: "Say Hello... or not. If you want to make the world aware of it you also could",
Flags: quicli.Flags{
{Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},
{Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},
{Name: "world", Description: "announce it to the world"},
},
}
cfg := cli.Parse()
```Real one-liner (Parse and run)
```golang
quicli.Run(quicli.Cli{Usage:"SayToTheWorld [flags]",Description: "Say Hello... or not. If you want to make the world aware of it you also could",Flags: quicli.Flags{{Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},{Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},{Name: "world", Description: "announce it to the world"},},Function: SayHello,})
```You want a subcommand pattern?! okay
```golang
cli := quicli.Cli{
Usage: "SayToTheWorld [command] [flags]",
Description: "Say Hello... or not. If you want to make the world aware of it you also could",
Flags: quicli.Flags{
{Name: "count", Default: 1, Description: "how many times I want to say it. Sometimes repetition is the key"},
{Name: "foreground", Description: "change foreground background", ForSubcommand: quicli.SubcommandSet{"color"}},
{Name: "say", Default: "hello", Description: "say something. If you are polite start with a greeting"},
{Name: "world", Description: "announce it to the world"},
{Name: "surprise", Description: "you will see my friend", ForSubcommand: quicli.SubcommandSet{"toto", "color"}, NotForRootCommand: true},
},
Function: Main,
Subcommands: quicli.Subcommands{
{Name: "color", Description: "print coloured message", Function: Color},
{Name: "toto", Description: "??", Function: Toto},
},
}
cli.RunWithSubcommand()
```### Use flag values in code
```golang
cfg.GetIntFlag("count") // get the --count flag value
// or alternatively
cfg.GetIntFlag("c")
```Get more [examples](examples/)
### Disclaimer
The library is a wrapper of the built-in go `flag` package. It should only be used to quickly built CLI and it is not intented for complex CLI usage.