forked from urfave/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.go
60 lines (54 loc) · 1.16 KB
/
cli.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
// Package cli provides a minimal framework for creating and organizing command line
// Go applications. cli is designed to be easy to understand and write, the most simple
// cli application can be written as follows:
//
// func main() {
// (&cli.Command{}).Run(context.Background(), os.Args)
// }
//
// Of course this application does not do much, so let's make this an actual application:
//
// func main() {
// cmd := &cli.Command{
// Name: "greet",
// Usage: "say a greeting",
// Action: func(c *cli.Context) error {
// fmt.Println("Greetings")
// return nil
// },
// }
//
// cmd.Run(context.Background(), os.Args)
// }
package cli
import (
"fmt"
"os"
"runtime"
"strings"
)
var isTracingOn = os.Getenv("URFAVE_CLI_TRACING") == "on"
func tracef(format string, a ...any) {
if !isTracingOn {
return
}
if !strings.HasSuffix(format, "\n") {
format = format + "\n"
}
pc, file, line, _ := runtime.Caller(1)
cf := runtime.FuncForPC(pc)
fmt.Fprintf(
os.Stderr,
strings.Join([]string{
"## URFAVE CLI TRACE ",
file,
":",
fmt.Sprintf("%v", line),
" ",
fmt.Sprintf("(%s)", cf.Name()),
" ",
format,
}, ""),
a...,
)
}