-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package os | ||
|
||
import ( | ||
"github.com/rsteube/carapace" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func ActionEnvironmentVariables() carapace.Action { | ||
return carapace.ActionCallback(func(args []string) carapace.Action { | ||
env := os.Environ() | ||
vars := make([]string, len(env)) | ||
for index, e := range os.Environ() { | ||
pair := strings.SplitN(e, "=", 2) | ||
vars[index] = pair[0] | ||
} | ||
return carapace.ActionValues(vars...) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace-bin/actions/os" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "sudo", | ||
Short: "execute a command as another user", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
func init() { | ||
carapace.Gen(rootCmd).Standalone() | ||
|
||
rootCmd.Flags().BoolP("askpass", "A", false, "use a helper program for password prompting") | ||
rootCmd.Flags().BoolP("background", "b", false, "run command in the background") | ||
rootCmd.Flags().BoolP("bell", "B", false, "ring bell when prompting") | ||
rootCmd.Flags().StringP("close-from", "C", "", "close all file descriptors >= num") | ||
rootCmd.Flags().BoolP("edit", "e", false, "edit files instead of running a command") | ||
rootCmd.Flags().StringP("group", "g", "", "run command as the specified group name or ID") | ||
rootCmd.Flags().BoolP("help", "h", false, "display help message and exit") | ||
rootCmd.Flags().String("host", "", "run command on host (if supported by plugin)") | ||
rootCmd.Flags().BoolP("list", "l", false, "list user's privileges or check a specific command; use twice for longer format") | ||
rootCmd.Flags().BoolP("login", "i", false, "run login shell as the target user; a command may also be specified") | ||
rootCmd.Flags().BoolP("non-interactive", "n", false, "non-interactive mode, no prompts are used") | ||
rootCmd.Flags().StringP("other-user", "U", "", "in list mode, display privileges for user") | ||
rootCmd.Flags().StringP("preserve-env", "E", "", "preserve user environment when running command") | ||
rootCmd.Flags().BoolP("preserve-groups", "P", false, "preserve group vector instead of setting to target's") | ||
rootCmd.Flags().StringP("prompt", "p", "", "use the specified password prompt") | ||
rootCmd.Flags().BoolP("remove-timestamp", "K", false, "remove timestamp file completely") | ||
rootCmd.Flags().BoolP("reset-timestamp", "k", false, "invalidate timestamp file") | ||
rootCmd.Flags().BoolP("set-home", "H", false, "set HOME variable to target user's home dir") | ||
rootCmd.Flags().BoolP("shell", "s", false, "run shell as the target user; a command may also be specified") | ||
rootCmd.Flags().BoolP("stdin", "S", false, "read password from standard input") | ||
rootCmd.Flags().StringP("user", "u", "", "run command (or edit file) as specified user name or ID") | ||
rootCmd.Flags().BoolP("validate", "v", false, "update user's timestamp without running a command") | ||
rootCmd.Flags().BoolP("version", "V", false, "display version information and exit") | ||
|
||
rootCmd.Flag("preserve-env").NoOptDefVal = " " | ||
|
||
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ | ||
"group": carapace.ActionGroups(), | ||
"other-user": carapace.ActionUsers(), | ||
"preserve-env": os.ActionEnvironmentVariables(), // TODO comma separated list | ||
"user": carapace.ActionUsers(), | ||
}) | ||
|
||
carapace.Gen(rootCmd).PositionalCompletion( | ||
carapace.ActionFiles(""), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/rsteube/carapace-bin/completers/sudo_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |