mirror of
https://github.com/dagucloud/dagu.git
synced 2026-12-05 21:34:48 +00:00
Add copyright and SPDX license identifier headers to all Go source files, test files, shell scripts, and proto files.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Copyright (C) 2026 Yota Hamada
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package cmdutil
|
|
|
|
import "strings"
|
|
|
|
// HasShellArgs reports whether a shell slice contains a non-empty argument
|
|
// that is not the "direct" shell placeholder.
|
|
func HasShellArgs(shell []string) bool {
|
|
for _, arg := range shell {
|
|
arg = strings.TrimSpace(arg)
|
|
if arg == "" {
|
|
continue
|
|
}
|
|
if isDirectShell(arg) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsShellValueSet checks whether a shell value from a generic config is non-empty
|
|
// and not the "direct" shell placeholder.
|
|
func IsShellValueSet(shellValue any) bool {
|
|
switch v := shellValue.(type) {
|
|
case string:
|
|
trimmed := strings.TrimSpace(v)
|
|
return trimmed != "" && !isDirectShell(trimmed)
|
|
case []string:
|
|
return HasShellArgs(v)
|
|
case []any:
|
|
for _, item := range v {
|
|
if s, ok := item.(string); ok {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
continue
|
|
}
|
|
if isDirectShell(s) {
|
|
return false
|
|
}
|
|
return true
|
|
} else if item != nil {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isDirectShell(value string) bool {
|
|
return value == "direct"
|
|
}
|