CMDR Documentation
The Documentation about cmdr
Keep It Simple
Define the CLI arguments with fluent style
POSIX-Compliant
Be compliant with POSIX Command-line conventions
Coding Loosely
Simply to migrate from standard library `flag`
Strong Hierarchical Configurations
Manage any hierarchical configurations with `Option Store`
Useful Debugging Information
Print full commands tree with `~~tree`, Dump the hit/parsed info with `~~debug`
Ready for Interceptions
Hook and customize the behaviors of `cmdr`
# News
- english documentation not completed yet
# Using cmdr
(opens new window)
package main
import (
"fmt"
"github.com/hedzr/cmdr"
"github.com/hedzr/cmdr/tool"
)
func main() {
if err := cmdr.Exec(buildRootCmd()); err != nil {
fmt.Printf("error: %+v\n", err)
}
}
func buildRootCmd() (rootCmd *cmdr.RootCommand) {
root := cmdr.
Root("test-app", "1.1").
Copyright("test-app is powered by cmdr", "hedzr").
Description("desc", "longDesc").
Examples("examples")
//.Action(func(cmd *cmdr.Command, args []string) (err error) { return; )
rootCmd = root.RootCommand()
cmdr.NewBool(false).
Titles("enable-ueh", "ueh").
EnvKeys("ENABLE_UEH").
Description("Enables the unhandled exception handler?").
AttachTo(root)
cmdr.NewCmd().
Titles("soundex", "snd", "sndx", "sound").
Description("soundex test").
Group("Test").
TailPlaceholder("[text1, text2, ...]").
Action(func(cmd *cmdr.Command, args []string) (err error) {
for ix, s := range args {
fmt.Printf("%5d. %s => %s\n", ix, s, tool.Soundex(s))
}
return
}).
AttachTo(root)
return
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
The screen looks like:
That's it!