-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpcmd.go
66 lines (49 loc) · 1.49 KB
/
helpcmd.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
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
)
func PrintUsage() {
// print the usage message
fmt.Println("Usage: chrono [command] [options]")
fmt.Println("Commands:")
fmt.Println(" stopwatch, sw Start the stopwatch")
fmt.Println(" countdown, cd Start the countdown timer")
fmt.Println(" help Show this help message")
fmt.Println("Options:")
fmt.Println(" -h, --help Show this help message")
}
func StopwatchHelp() {
fmt.Println("Usage: chrono stopwatch [options]")
fmt.Println("Options:")
fmt.Println(" -r, --resume Resume the stopwatch from the last saved time")
fmt.Println(" -h, --help Show this help message")
// exit the program
os.Exit(0)
}
func CountdownTimerHelp() {
fmt.Println("Usage: chrono countdown [options]")
fmt.Println("Options:")
fmt.Println(" [time] The integer value of the time in seconds to count down from")
fmt.Println(" -h, --help Show this help message")
// exit the program
os.Exit(0)
}
func CheckHelpFlag() {
// check if the help flag is passed as the first argument
if len(os.Args) > 1 && (os.Args[1] == "-h" || os.Args[1] == "--help" || os.Args[1] == "help") {
PrintUsage()
return
}
if len(os.Args) > 2 && (os.Args[2] == "-h" || os.Args[2] == "--help" || os.Args[2] == "help") {
if os.Args[1] == "stopwatch" || os.Args[1] == "sw" {
println("here")
StopwatchHelp()
return
}
if os.Args[1] == "countdown" || os.Args[1] == "cd" || os.Args[1] == "timer" {
CountdownTimerHelp()
return
}
}
}