https://github.com/shafreeck/cortana
cortana gives you a new style to write command line programs
https://github.com/shafreeck/cortana
command command-line command-line-tool flags go golang
Last synced: about 1 year ago
JSON representation
cortana gives you a new style to write command line programs
- Host: GitHub
- URL: https://github.com/shafreeck/cortana
- Owner: shafreeck
- License: apache-2.0
- Created: 2020-08-19T16:47:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-05T10:43:05.000Z (about 3 years ago)
- Last Synced: 2025-03-20T22:23:03.357Z (about 1 year ago)
- Topics: command, command-line, command-line-tool, flags, go, golang
- Language: Go
- Homepage:
- Size: 111 KB
- Stars: 30
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cortana
An extremely easy to use command line parsing library
# Features
* Extremely easy to use
* Handling the sub commands exactly the same as the main command
* Parse args from configration file, envrionment and flags
## How to use
### Work in the main function
```go
// say.go
func main() {
args := struct {
Name string `cortana:"--name, -n, tom, who do you want say to"`
Text string `cortana:"text"`
}{}
// Parse the args
cortana.Parse(&args)
fmt.Printf("Say to %s: %s\n", args.Name, args.Text)
}
$ go run say.go -n alice hello
Say to alice: hello
```
### Use as the sub-command
```go
// pepole.go
func say() {
args := struct {
Name string `cortana:"--name, -n, tom, who do you want say to"`
Text string `cortana:"text"`
}{}
cortana.Parse(&args)
fmt.Printf("Say to %s: %s\n", args.Name, args.Text)
}
func main() {
// Add "say" as a sub-command
cortana.AddCommand("say", say, "say something")
cortana.Launch()
}
$ go run pepole.go say -n alice hello
Say to alice: hello
```
### You defines how the sub-commond looks like without affecting the original implementation
```go
// people.go
func main() {
// say greeting works by calling the say function
cortana.AddCommand("say greeting", say, "say something")
// greeting say also works by calling the say function
cortana.AddCommand("greeting say", say, "say something")
cortana.Launch()
}
$ go run pepole.go say greeting -n alice hello
Say to alice: hello
$ go run pepole.go greeting say -n alice hello
Say to alice: hello
```