-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.go
More file actions
60 lines (49 loc) · 1.19 KB
/
utils.go
File metadata and controls
60 lines (49 loc) · 1.19 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
package parser
import (
"fmt"
"log"
"strconv"
"github.com/drycc/workflow-cli/cmd"
)
func safeGetString(args map[string]interface{}, key string) string {
return safeGetValue(args, key, "")
}
func safeGetBool(args map[string]interface{}, key string) bool {
return safeGetValue(args, key, false)
}
func safeGetInt(args map[string]interface{}, key string) int {
if args[key] == nil {
return 0
}
retVal, err := strconv.Atoi(args[key].(string))
if err != nil {
log.Fatalf("could not convert %s to int: %v", args[key], err)
}
return retVal
}
func safeGetValue[T any](args map[string]interface{}, key string, defaultValue T) T {
if args[key] == nil {
return defaultValue
}
return args[key].(T)
}
func responseLimit(limit string) (int, error) {
if limit == "" {
return -1, nil
}
return strconv.Atoi(limit)
}
// PrintUsage runs if no matching command is found.
func PrintUsage(cmdr cmd.Commander) {
cmdr.PrintErrln("Found no matching command, try 'drycc help'")
cmdr.PrintErrln("Usage: drycc <command> [<args>...]")
}
func printHelp(argv []string, usage string) bool {
if len(argv) > 1 {
if argv[1] == "--help" || argv[1] == "-h" {
fmt.Print(usage)
return true
}
}
return false
}