forked from micromdm/micromdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdmdctl.go
More file actions
87 lines (79 loc) · 1.54 KB
/
Copy pathmdmdctl.go
File metadata and controls
87 lines (79 loc) · 1.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"fmt"
"os"
"strings"
"text/tabwriter"
"github.com/micromdm/go4/version"
)
func main() {
if len(os.Args) < 2 {
usage()
os.Exit(1)
}
if strings.ToLower(os.Args[1]) != "config" {
checkForOldConfig()
}
var run func([]string) error
switch strings.ToLower(os.Args[1]) {
case "version", "-version":
version.Print()
return
case "config":
cmd := new(configCommand)
run = cmd.Run
case "get":
cmd := new(getCommand)
run = cmd.Run
case "apply":
cmd := new(applyCommand)
run = cmd.Run
case "remove":
cmd := new(removeCommand)
run = cmd.Run
case "mdmcert":
cmd := new(mdmcertCommand)
run = cmd.Run
case "mdmcert.download":
cmd := new(mdmcertDownloadCommand)
run = cmd.Run
default:
usage()
os.Exit(1)
}
if err := run(os.Args[2:]); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
func usage() error {
helpText := `USAGE: mdmctl <COMMAND>
Available Commands:
get
apply
config
remove
mdmcert
mdmcert.download
version
Use mdmctl <command> -h for additional usage of each command.
Example: mdmctl get devices
`
fmt.Println(helpText)
return nil
}
func usageFor(fs *flag.FlagSet, short string) func() {
return func() {
fmt.Fprintf(os.Stderr, "USAGE\n")
fmt.Fprintf(os.Stderr, " %s\n", short)
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "FLAGS\n")
w := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
fs.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(w, "\t-%s %s\t%s\n", f.Name, f.DefValue, f.Usage)
})
w.Flush()
fmt.Fprintf(os.Stderr, "\n")
}
}