diff --git a/cmd/cli/commands.go b/cmd/cli/commands.go index 2b43320..3733f71 100644 --- a/cmd/cli/commands.go +++ b/cmd/cli/commands.go @@ -207,9 +207,7 @@ func initStartCmd() *cobra.Command { NOTE: running "ctrld start" without any arguments will start already installed ctrld service.`, Args: func(cmd *cobra.Command, args []string) error { - args = slices.DeleteFunc(args, func(arg string) bool { - return arg == "" - }) + args = filterEmptyStrings(args) if len(args) > 0 { return fmt.Errorf("'ctrld start' doesn't accept positional arguments\n" + "Use flags instead (e.g. --cd, --iface) or see 'ctrld start --help' for all options") @@ -223,6 +221,7 @@ NOTE: running "ctrld start" without any arguments will start already installed c sc := &service.Config{} *sc = *svcConfig osArgs := os.Args[2:] + osArgs = filterEmptyStrings(osArgs) if os.Args[1] == "service" { osArgs = os.Args[3:] } @@ -570,9 +569,7 @@ NOTE: running "ctrld start" without any arguments will start already installed c NOTE: running "ctrld start" without any arguments will start already installed ctrld service.`, Args: func(cmd *cobra.Command, args []string) error { - args = slices.DeleteFunc(args, func(arg string) bool { - return arg == "" - }) + args = filterEmptyStrings(args) if len(args) > 0 { return fmt.Errorf("'ctrld start' doesn't accept positional arguments\n" + "Use flags instead (e.g. --cd, --iface) or see 'ctrld start --help' for all options") @@ -1388,3 +1385,11 @@ func initServicesCmd(commands ...*cobra.Command) *cobra.Command { return serviceCmd } + +// filterEmptyStrings removes empty strings from a slice of strings. +// It returns a new slice containing only non-empty strings. +func filterEmptyStrings(slice []string) []string { + return slices.DeleteFunc(slice, func(s string) bool { + return s == "" + }) +}