@@ -19,11 +19,21 @@ func newSudoersCommand() *cobra.Command {
19
19
networksMD = filepath .Join (prefixDir , "share/doc/lima/docs/network.md" )
20
20
}
21
21
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.\n See %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 ,
27
37
}
28
38
configFile , _ := networks .ConfigFile ()
29
39
sudoersCommand .Flags ().Bool ("check" , false ,
@@ -42,6 +52,14 @@ func sudoersAction(cmd *cobra.Command, args []string) error {
42
52
if check {
43
53
return verifySudoAccess (args )
44
54
}
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
+ }
45
63
sudoers , err := networks .Sudoers ()
46
64
if err != nil {
47
65
return err
0 commit comments