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:
parent
fec4864771
commit
0080ea5a20
4 changed files with 118 additions and 107 deletions
util
20
util/util.go
20
util/util.go
|
@ -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, " ")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue