-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (32 loc) · 844 Bytes
/
main.go
File metadata and controls
36 lines (32 loc) · 844 Bytes
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
//go:build ignore
// this is show case for a little bit complex than 'basic'
//
// which disabled the default help menu entry '-h' or '--help',
//
// instead, it use '-help' and '--help-me' as help menu entry and handle help print manually
//
// also, it pass 'os.Args[1:]' manually to 'Parse' method, which is the same as pass 'nil'
package main
import (
"fmt"
"os"
"github.com/hellflame/argparse"
)
func main() {
parser := argparse.NewParser("", "this is a basic program", &argparse.ParserConfig{
DisableHelp: true,
DisableDefaultShowHelp: true})
name := parser.String("n", "name", nil)
help := parser.Flag("help", "help-me", nil)
if e := parser.Parse(os.Args[1:]); e != nil {
fmt.Println(e.Error())
return
}
if *help {
parser.PrintHelp()
return
}
if *name != "" {
fmt.Printf("hello %s\n", *name)
}
}