From 7c84bc48dc01452ce28d4e022de5f53cf9c37c1c Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 11 Apr 2025 21:04:37 +0300 Subject: [PATCH] sudoers: show the command only on darwin Signed-off-by: Oleksandr Redko --- .ls-lint.yml | 4 ++-- cmd/limactl/main.go | 5 ++--- cmd/limactl/main_darwin.go | 13 +++++++++++++ cmd/limactl/main_linux.go | 12 ++++++++++++ cmd/limactl/main_windows.go | 10 ++++++++++ .../{start-at-login.go => start-at-login_unix.go} | 2 ++ cmd/limactl/{sudoers.go => sudoers_darwin.go} | 4 ---- 7 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 cmd/limactl/main_darwin.go create mode 100644 cmd/limactl/main_linux.go create mode 100644 cmd/limactl/main_windows.go rename cmd/limactl/{start-at-login.go => start-at-login_unix.go} (99%) rename cmd/limactl/{sudoers.go => sudoers_darwin.go} (95%) diff --git a/.ls-lint.yml b/.ls-lint.yml index 613cb57fdc2..6f9a0898cf9 100644 --- a/.ls-lint.yml +++ b/.ls-lint.yml @@ -13,8 +13,8 @@ ls: .yaml: snake_case cmd/limactl: - # valid names are `show-ssh.go` or `show-ssh_test.go` - .go: kebab-case | regex:[a-z0-9-]+_test + # valid names are `show-ssh.go`, `show-ssh_windows.go` or `show-ssh_test.go` + .go: lowercase docs: .md: kebab-case diff --git a/cmd/limactl/main.go b/cmd/limactl/main.go index c70cf9c4e0e..f98c313f5b0 100644 --- a/cmd/limactl/main.go +++ b/cmd/limactl/main.go @@ -169,7 +169,6 @@ func newApp() *cobra.Command { newListCommand(), newDeleteCommand(), newValidateCommand(), - newSudoersCommand(), newPruneCommand(), newHostagentCommand(), newInfoCommand(), @@ -188,8 +187,8 @@ func newApp() *cobra.Command { newTemplateCommand(), newRestartCommand(), ) - if runtime.GOOS == "darwin" || runtime.GOOS == "linux" { - rootCmd.AddCommand(startAtLoginCommand()) + for _, cmd := range additionalAdvancedCommands() { + rootCmd.AddCommand(cmd) } return rootCmd diff --git a/cmd/limactl/main_darwin.go b/cmd/limactl/main_darwin.go new file mode 100644 index 00000000000..f3849d20c8c --- /dev/null +++ b/cmd/limactl/main_darwin.go @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: Copyright The Lima Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import "github.com/spf13/cobra" + +func additionalAdvancedCommands() []*cobra.Command { + return []*cobra.Command{ + newSudoersCommand(), + startAtLoginCommand(), + } +} diff --git a/cmd/limactl/main_linux.go b/cmd/limactl/main_linux.go new file mode 100644 index 00000000000..f09c3ea77df --- /dev/null +++ b/cmd/limactl/main_linux.go @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright The Lima Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import "github.com/spf13/cobra" + +func additionalAdvancedCommands() []*cobra.Command { + return []*cobra.Command{ + startAtLoginCommand(), + } +} diff --git a/cmd/limactl/main_windows.go b/cmd/limactl/main_windows.go new file mode 100644 index 00000000000..bf3bba338ef --- /dev/null +++ b/cmd/limactl/main_windows.go @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: Copyright The Lima Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import "github.com/spf13/cobra" + +func additionalAdvancedCommands() []*cobra.Command { + return nil +} diff --git a/cmd/limactl/start-at-login.go b/cmd/limactl/start-at-login_unix.go similarity index 99% rename from cmd/limactl/start-at-login.go rename to cmd/limactl/start-at-login_unix.go index 39db8bbbedb..b6e0e0aed6d 100644 --- a/cmd/limactl/start-at-login.go +++ b/cmd/limactl/start-at-login_unix.go @@ -1,3 +1,5 @@ +//go:build !windows + // SPDX-FileCopyrightText: Copyright The Lima Authors // SPDX-License-Identifier: Apache-2.0 diff --git a/cmd/limactl/sudoers.go b/cmd/limactl/sudoers_darwin.go similarity index 95% rename from cmd/limactl/sudoers.go rename to cmd/limactl/sudoers_darwin.go index 4d6dc7b34a2..dfe3ba7068d 100644 --- a/cmd/limactl/sudoers.go +++ b/cmd/limactl/sudoers_darwin.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "runtime" "github.com/lima-vm/lima/pkg/networks" "github.com/sirupsen/logrus" @@ -42,9 +41,6 @@ See %s for the usage.`, networksURL), } func sudoersAction(cmd *cobra.Command, args []string) error { - if runtime.GOOS != "darwin" { - return errors.New("sudoers command is only supported on macOS right now") - } nwCfg, err := networks.LoadConfig() if err != nil { return err