-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_args.go
More file actions
56 lines (44 loc) · 1.23 KB
/
cli_args.go
File metadata and controls
56 lines (44 loc) · 1.23 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"fmt"
"os"
)
type cli_args struct {
dry_run bool
recursive string
version bool
}
func get_cli_args() (args cli_args) {
args = cli_args{}
flag.StringVar(&args.recursive, "r", "", "apply tidynames recursively in the given dir")
flag.StringVar(&args.recursive, "recursive", "", "apply tidynames recursively in the given dir")
flag.BoolVar(&args.dry_run, "n", false, "just print changes - do not rename")
flag.BoolVar(&args.dry_run, "noop", false, "just print changes - do not rename")
flag.BoolVar(&args.version, "v", false, "print the version of tidynames")
flag.BoolVar(&args.version, "version", false, "print the version of tidynames")
flag.Parse()
return
}
func (args cli_args) evalute() (err error) {
tc := tidy_config{
replacement_char: '_',
}
if args.version {
fmt.Printf("%s %s, commit: %s, build at: %s.\n", os.Args[0], version, commit, date)
os.Exit(0)
}
if len(args.recursive) > 0 {
err = fmt.Errorf("%s - Recursive tidying is not implemented yet.\n", os.Args[0])
return
}
if flag.NArg() == 0 {
err = fmt.Errorf("%s - Missing arguments.\n", os.Args[0])
return
}
if args.dry_run {
fmt.Printf("[dry run]\n")
}
tc.tidy_entries(args, flag.Args(), os.Stdout)
return
}