Skip to content

Commit 81bd8e5

Browse files
committed
limactl sudoers: improve --help message
Signed-off-by: Akihiro Suda <[email protected]>
1 parent e75b0ea commit 81bd8e5

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cmd/limactl/sudoers.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ func newSudoersCommand() *cobra.Command {
1919
networksMD = filepath.Join(prefixDir, "share/doc/lima/docs/network.md")
2020
}
2121
sudoersCommand := &cobra.Command{
22-
Use: "sudoers [SUDOERSFILE]",
23-
Short: "Generate /etc/sudoers.d/lima file for enabling vmnet.framework support",
24-
Long: fmt.Sprintf("Generate /etc/sudoers.d/lima file for enabling vmnet.framework support.\nSee %s for the usage.", networksMD),
25-
Args: cobra.MaximumNArgs(1),
26-
RunE: sudoersAction,
22+
Use: "sudoers [--check [SUDOERSFILE-TO-CHECK]]",
23+
Example: `
24+
To generate the /etc/sudoers.d/lima file:
25+
$ limactl sudoers | sudo tee /etc/sudoers.d/lima
26+
27+
To validate the existing /etc/sudoers.d/lima file:
28+
$ limactl sudoers --check /etc/sudoers.d/lima
29+
`,
30+
Short: "Generate the content of the /etc/sudoers.d/lima file",
31+
Long: fmt.Sprintf(`Generate the content of the /etc/sudoers.d/lima file for enabling vmnet.framework support.
32+
The content is written to stdout, NOT to the file.
33+
This command must not run as the root.
34+
See %s for the usage.`, networksMD),
35+
Args: cobra.MaximumNArgs(1),
36+
RunE: sudoersAction,
2737
}
2838
configFile, _ := networks.ConfigFile()
2939
sudoersCommand.Flags().Bool("check", false,
@@ -42,6 +52,14 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
4252
if check {
4353
return verifySudoAccess(args)
4454
}
55+
switch len(args) {
56+
case 0:
57+
// NOP
58+
case 1:
59+
return fmt.Errorf("the file argument can be specified only for --check mode")
60+
default:
61+
return fmt.Errorf("unexpected arguments %v", args)
62+
}
4563
sudoers, err := networks.Sudoers()
4664
if err != nil {
4765
return err

0 commit comments

Comments
 (0)