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)
| 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. |
| 952 | func 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. |
no test coverage detected