mirror of
https://github.com/taigrr/systemctl.git
synced 2026-03-09 00:14:38 -07:00
feat: add optional variadic args to all commands (#8)
Allow callers to pass additional systemctl flags (e.g. --no-block, --force) via variadic string args on every exported function. This is backward-compatible: existing callers without extra args continue to work unchanged. Introduces a prepareArgs helper to centralize argument construction, replacing the duplicated args/UserMode pattern across all functions. Closes #2
This commit is contained in:
14
util.go
14
util.go
@@ -55,6 +55,20 @@ func execute(ctx context.Context, args []string) (string, string, int, error) {
|
||||
return output, warnings, code, err
|
||||
}
|
||||
|
||||
// prepareArgs builds the systemctl command arguments from a base command,
|
||||
// options, and any additional arguments the caller wants to pass through.
|
||||
func prepareArgs(base string, opts Options, extra ...string) []string {
|
||||
args := make([]string, 0, 2+len(extra))
|
||||
args = append(args, base)
|
||||
if opts.UserMode {
|
||||
args = append(args, "--user")
|
||||
} else {
|
||||
args = append(args, "--system")
|
||||
}
|
||||
args = append(args, extra...)
|
||||
return args
|
||||
}
|
||||
|
||||
func filterErr(stderr string) error {
|
||||
switch {
|
||||
case strings.Contains(stderr, `does not exist`):
|
||||
|
||||
Reference in New Issue
Block a user