package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/lima-vm/lima/v2/pkg/networks"
)
const socketVMNetURL = "https://lima-vm.io/docs/config/network/vmnet/#socket_vmnet"
func newSudoersCommand() *cobra.Command {
sudoersCommand := &cobra.Command{
Use: "sudoers [--check [SUDOERSFILE-TO-CHECK]]",
Example: `
To generate the /etc/sudoers.d/lima file:
$ limactl sudoers | sudo tee /etc/sudoers.d/lima
To validate the existing /etc/sudoers.d/lima file:
$ limactl sudoers --check /etc/sudoers.d/lima
`,
Short: "Generate the content of the /etc/sudoers.d/lima file",
Long: fmt.Sprintf(`Generate the content of the /etc/sudoers.d/lima file for enabling vmnet.framework support (socket_vmnet) on macOS.
The content is written to stdout, NOT to the file.
This command must not run as the root user.
See %s for the usage.`, socketVMNetURL),
Args: WrapArgsError(cobra.MaximumNArgs(1)),
RunE: sudoersAction,
GroupID: advancedCommand,
}
cfgFile, _ := networks.ConfigFile()
sudoersCommand.Flags().Bool("check", false,
fmt.Sprintf("check that the sudoers file is up-to-date with %q", cfgFile))
return sudoersCommand
}