Files
dagu/internal/cmn/cmdutil/shellutil.go
Yota Hamada b581118067 chore: add GPL-3.0 license headers to source files
Add copyright and SPDX license identifier headers to all Go source
files, test files, shell scripts, and proto files.
2026-03-09 18:38:11 +09:00

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"
}