-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.go
54 lines (41 loc) · 854 Bytes
/
arguments.go
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
package main
import (
"flag"
"fmt"
"log"
"os"
)
type Arguments struct {
ShowFree bool
ShowUsed bool
}
var usage = `
Usage: %s [options]
Options:
-free Show free GPUs.
-used Show used GPUs.
Examples:
To show all servers and GPUs run:
%[1]s
To show only free GPUs run:
%[1]s -free
To show only used GPUs run:
%[1]s -used
`
func ParseArguments() Arguments {
var args Arguments
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage, os.Args[0])
// flag.PrintDefaults()
}
flag.BoolVar(&args.ShowFree, "free", false, "Show free GPUs.")
flag.BoolVar(&args.ShowUsed, "used", false, "Show used GPUs.")
flag.Parse()
checkArguments(args)
return args
}
func checkArguments(args Arguments) {
if args.ShowFree && args.ShowUsed {
log.Fatalf("Cannot use both -free and -used flags.")
}
}