1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-25 00:07:36 +02:00

All --wait-cmd

This commit is contained in:
Philipp Heckel 2022-06-20 23:03:16 -04:00
parent fec4864771
commit 0080ea5a20
4 changed files with 118 additions and 107 deletions

View file

@ -26,6 +26,7 @@ var (
randomMutex = sync.Mutex{}
sizeStrRegex = regexp.MustCompile(`(?i)^(\d+)([gmkb])?$`)
errInvalidPriority = errors.New("invalid priority")
noQuotesRegex = regexp.MustCompile(`^[-_./:@a-zA-Z0-9]+$`)
)
// FileExists checks if a file exists, and returns true if it does
@ -286,3 +287,22 @@ func MaybeMarshalJSON(v interface{}) string {
}
return string(jsonBytes)
}
// QuoteCommand combines a command array to a string, quoting arguments that need quoting.
// This function is naive, and sometimes wrong. It is only meant for lo pretty-printing a command.
//
// Warning: Never use this function with the intent to run the resulting command.
//
// Example:
// []string{"ls", "-al", "Document Folder"} -> ls -al "Document Folder"
func QuoteCommand(command []string) string {
var quoted []string
for _, c := range command {
if noQuotesRegex.MatchString(c) {
quoted = append(quoted, c)
} else {
quoted = append(quoted, fmt.Sprintf(`"%s"`, c))
}
}
return strings.Join(quoted, " ")
}