From da7e404bcffe49240554888b1ca665030073799b Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 15 Jul 2024 23:29:21 +0900 Subject: 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 --- cli.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'cli.go') 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) } } -- cgit v1.3.1