aboutsummaryrefslogtreecommitdiffhomepage
path: root/cli.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-07-15 23:29:21 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-07-15 23:29:21 +0900
commitda7e404bcffe49240554888b1ca665030073799b (patch)
treeca9f296b59e6632f4ebf0fe6e4069744f8d90fef /cli.go
parent1cd0846dc92fdcf43ea25bf0013e2681d0b7903d (diff)
main: implement sudo and machinectl launcher methods
This does almost exactly what github:intgr/ego does, with some minor optimisations and corrections. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'cli.go')
-rw-r--r--cli.go22
1 files changed, 3 insertions, 19 deletions
diff --git a/cli.go b/cli.go
index e85917e1..9a4d3a01 100644
--- a/cli.go
+++ b/cli.go
@@ -9,26 +9,17 @@ import (
)
var (
- ego *user.User
- command []string
- verbose bool
- method = machinectl
-
userName string
methodFlags [2]bool
printVersion bool
-)
-
-const (
- machinectl uint8 = iota
- machinectlBare
- sudo
+ mustPulse bool
)
func init() {
flag.StringVar(&userName, "u", "ego", "Specify a username")
flag.BoolVar(&methodFlags[0], "sudo", false, "Use 'sudo' to change user")
flag.BoolVar(&methodFlags[1], "bare", false, "Use 'machinectl' but skip xdg-desktop-portal setup")
+ flag.BoolVar(&mustPulse, "pulse", false, "Treat unavailable PulseAudio as fatal")
flag.BoolVar(&verbose, "v", false, "Verbose output")
flag.BoolVar(&printVersion, "V", false, "Print version")
}
@@ -41,13 +32,6 @@ func copyArgs() {
command = flag.Args()
- switch { // zero value is machinectl
- case methodFlags[0]:
- method = sudo
- case methodFlags[1]:
- method = machinectlBare
- }
-
if u, err := user.Lookup(userName); err != nil {
if errors.As(err, new(user.UnknownUserError)) {
fmt.Println("unknown user", userName)
@@ -62,6 +46,6 @@ func copyArgs() {
}
if verbose {
- fmt.Println("Running command", command, "as user", ego.Username, "("+ego.Uid+")")
+ fmt.Println("Running as user", ego.Username, "("+ego.Uid+"),", "command:", command)
}
}