MCPcopy
hub / github.com/spf13/cobra / CompDebug

Function CompDebug

completions.go:952–970  ·  completions.go::CompDebug

CompDebug prints the specified string to the same file as where the completion script prints its logs. Note that completion printouts should never be on stdout as they would be wrongly interpreted as actual completion choices by the completion script.

(msg string, printToStdErr bool)

Source from the content-addressed store, hash-verified

950// Note that completion printouts should never be on stdout as they would
951// be wrongly interpreted as actual completion choices by the completion script.
952func CompDebug(msg string, printToStdErr bool) {
953 msg = fmt.Sprintf("[Debug] %s", msg)
954
955 // Such logs are only printed when the user has set the environment
956 // variable BASH_COMP_DEBUG_FILE to the path of some file to be used.
957 if path := os.Getenv("BASH_COMP_DEBUG_FILE"); path != "" {
958 f, err := os.OpenFile(path,
959 os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
960 if err == nil {
961 defer f.Close()
962 WriteStringAndCheck(f, msg)
963 }
964 }
965
966 if printToStdErr {
967 // Must print to stderr for this not to be read by the completion script.
968 fmt.Fprint(os.Stderr, msg)
969 }
970}
971
972// CompDebugln prints the specified string with a newline at the end
973// to the same file as where the completion script prints its logs.

Callers 2

CompDebuglnFunction · 0.85
CompErrorFunction · 0.85

Calls 1

WriteStringAndCheckFunction · 0.85

Tested by

no test coverage detected