Skip to content

Commit d5601c6

Browse files
authored
Merge pull request #3502 from AkihiroSuda/fix-3436
website: add back `limactl sudoers`
2 parents 5688cb4 + bc00cf7 commit d5601c6

10 files changed

+104
-88
lines changed

cmd/limactl/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ func newApp() *cobra.Command {
186186
newTunnelCommand(),
187187
newTemplateCommand(),
188188
newRestartCommand(),
189+
newSudoersCommand(),
190+
newStartAtLoginCommand(),
189191
)
190-
for _, cmd := range additionalAdvancedCommands() {
191-
rootCmd.AddCommand(cmd)
192-
}
193192

194193
return rootCmd
195194
}

cmd/limactl/main_darwin.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

cmd/limactl/main_linux.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

cmd/limactl/main_windows.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

cmd/limactl/start-at-login.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func newStartAtLoginCommand() *cobra.Command {
11+
startAtLoginCommand := &cobra.Command{
12+
Use: "start-at-login INSTANCE",
13+
Short: "Register/Unregister an autostart file for the instance",
14+
Args: WrapArgsError(cobra.MaximumNArgs(1)),
15+
RunE: startAtLoginAction,
16+
ValidArgsFunction: startAtLoginComplete,
17+
GroupID: advancedCommand,
18+
}
19+
20+
startAtLoginCommand.Flags().Bool(
21+
"enabled", true,
22+
"Automatically start the instance when the user logs in",
23+
)
24+
25+
return startAtLoginCommand
26+
}
27+
28+
func startAtLoginComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
29+
return bashCompleteInstanceNames(cmd)
30+
}

cmd/limactl/start-at-login_unix.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@ import (
1616
"github.com/spf13/cobra"
1717
)
1818

19-
func startAtLoginCommand() *cobra.Command {
20-
startAtLoginCommand := &cobra.Command{
21-
Use: "start-at-login INSTANCE",
22-
Short: "Register/Unregister an autostart file for the instance",
23-
Args: WrapArgsError(cobra.MaximumNArgs(1)),
24-
RunE: startAtLoginAction,
25-
ValidArgsFunction: startAtLoginComplete,
26-
GroupID: advancedCommand,
27-
}
28-
29-
startAtLoginCommand.Flags().Bool(
30-
"enabled", true,
31-
"Automatically start the instance when the user logs in",
32-
)
33-
34-
return startAtLoginCommand
35-
}
36-
3719
func startAtLoginAction(cmd *cobra.Command, args []string) error {
3820
instName := DefaultInstanceName
3921
if len(args) > 0 {
@@ -71,7 +53,3 @@ func startAtLoginAction(cmd *cobra.Command, args []string) error {
7153

7254
return nil
7355
}
74-
75-
func startAtLoginComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
76-
return bashCompleteInstanceNames(cmd)
77-
}

cmd/limactl/start-at-login_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"errors"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func startAtLoginAction(_ *cobra.Command, _ []string) error {
13+
return errors.New("start-at-login command is only supported on macOS and Linux right now")
14+
}

cmd/limactl/sudoers.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/lima-vm/lima/pkg/networks"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
const socketVMNetURL = "https://lima-vm.io/docs/config/network/vmnet/#socket_vmnet"
14+
15+
// newSudoersCommand is specific to macOS, but the help message is
16+
// compiled on Linux too, as depended by `make docsy`.
17+
// https://github.com/lima-vm/lima/issues/3436
18+
func newSudoersCommand() *cobra.Command {
19+
sudoersCommand := &cobra.Command{
20+
Use: "sudoers [--check [SUDOERSFILE-TO-CHECK]]",
21+
Example: `
22+
To generate the /etc/sudoers.d/lima file:
23+
$ limactl sudoers | sudo tee /etc/sudoers.d/lima
24+
25+
To validate the existing /etc/sudoers.d/lima file:
26+
$ limactl sudoers --check /etc/sudoers.d/lima
27+
`,
28+
Short: "Generate the content of the /etc/sudoers.d/lima file",
29+
Long: fmt.Sprintf(`Generate the content of the /etc/sudoers.d/lima file for enabling vmnet.framework support (socket_vmnet) on macOS.
30+
The content is written to stdout, NOT to the file.
31+
This command must not run as the root user.
32+
See %s for the usage.`, socketVMNetURL),
33+
Args: WrapArgsError(cobra.MaximumNArgs(1)),
34+
RunE: sudoersAction,
35+
GroupID: advancedCommand,
36+
}
37+
cfgFile, _ := networks.ConfigFile()
38+
sudoersCommand.Flags().Bool("check", false,
39+
fmt.Sprintf("check that the sudoers file is up-to-date with %q", cfgFile))
40+
return sudoersCommand
41+
}

cmd/limactl/sudoers_darwin.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,14 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16-
const networksURL = "https://lima-vm.io/docs/config/network/#socket_vmnet"
17-
18-
func newSudoersCommand() *cobra.Command {
19-
sudoersCommand := &cobra.Command{
20-
Use: "sudoers [--check [SUDOERSFILE-TO-CHECK]]",
21-
Example: `
22-
To generate the /etc/sudoers.d/lima file:
23-
$ limactl sudoers | sudo tee /etc/sudoers.d/lima
24-
25-
To validate the existing /etc/sudoers.d/lima file:
26-
$ limactl sudoers --check /etc/sudoers.d/lima
27-
`,
28-
Short: "Generate the content of the /etc/sudoers.d/lima file",
29-
Long: fmt.Sprintf(`Generate the content of the /etc/sudoers.d/lima file for enabling vmnet.framework support.
30-
The content is written to stdout, NOT to the file.
31-
This command must not run as the root user.
32-
See %s for the usage.`, networksURL),
33-
Args: WrapArgsError(cobra.MaximumNArgs(1)),
34-
RunE: sudoersAction,
35-
GroupID: advancedCommand,
36-
}
37-
cfgFile, _ := networks.ConfigFile()
38-
sudoersCommand.Flags().Bool("check", false,
39-
fmt.Sprintf("check that the sudoers file is up-to-date with %q", cfgFile))
40-
return sudoersCommand
41-
}
42-
4316
func sudoersAction(cmd *cobra.Command, args []string) error {
4417
nwCfg, err := networks.LoadConfig()
4518
if err != nil {
4619
return err
4720
}
4821
// Make sure the current network configuration is secure
4922
if err := nwCfg.Validate(); err != nil {
50-
logrus.Infof("Please check %s for more information.", networksURL)
23+
logrus.Infof("Please check %s for more information.", socketVMNetURL)
5124
return err
5225
}
5326
check, err := cmd.Flags().GetBool("check")

cmd/limactl/sudoers_nodarwin.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build !darwin
2+
3+
// SPDX-FileCopyrightText: Copyright The Lima Authors
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package main
7+
8+
import (
9+
"errors"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func sudoersAction(_ *cobra.Command, _ []string) error {
15+
return errors.New("sudoers command is only supported on macOS right now")
16+
}

0 commit comments

Comments
 (0)