From d2575b670835fd19f7a67e5eee476a46eb9822e5 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sat, 12 Oct 2024 01:28:22 +0900 Subject: [PATCH] fortify: move flag handling to separate files Signed-off-by: Ophestra Umiker --- flag.go => config.go | 11 +++-------- main.go | 9 +++------ version.go | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 14 deletions(-) rename flag.go => config.go (90%) create mode 100644 version.go diff --git a/flag.go b/config.go similarity index 90% rename from flag.go rename to config.go index 673601d..c5a5897 100644 --- a/flag.go +++ b/config.go @@ -7,7 +7,6 @@ import ( ) var ( - userName string confPath string dbusConfigSession string @@ -16,19 +15,17 @@ var ( dbusID string mpris bool + userName string mustWayland bool mustX bool mustDBus bool mustPulse bool - flagVerbose bool - printVersion bool - launchMethodText string ) func init() { - flag.StringVar(&userName, "u", "chronos", "Passwd name of user to run as") + // config file, disables every other flag here flag.StringVar(&confPath, "c", "nil", "Path to full app configuration, or \"nil\" to configure from flags") flag.StringVar(&dbusConfigSession, "dbus-config", "builtin", "Path to D-Bus proxy config file, or \"builtin\" for defaults") @@ -37,13 +34,11 @@ func init() { flag.StringVar(&dbusID, "dbus-id", "", "D-Bus ID of application, leave empty to disable own paths, has no effect if custom config is available") flag.BoolVar(&mpris, "mpris", false, "Allow owning MPRIS D-Bus path, has no effect if custom config is available") + flag.StringVar(&userName, "u", "chronos", "Passwd name of user to run as") flag.BoolVar(&mustWayland, "wayland", false, "Share Wayland socket") flag.BoolVar(&mustX, "X", false, "Share X11 socket and allow connection") flag.BoolVar(&mustDBus, "dbus", false, "Proxy D-Bus connection") flag.BoolVar(&mustPulse, "pulse", false, "Share PulseAudio socket and cookie") - - flag.BoolVar(&flagVerbose, "v", false, "Verbose output") - flag.BoolVar(&printVersion, "V", false, "Print version") } func init() { diff --git a/main.go b/main.go index c30bfca..45fbd21 100644 --- a/main.go +++ b/main.go @@ -16,14 +16,11 @@ import ( ) var ( - Version = "impure" + flagVerbose bool ) -func tryVersion() { - if printVersion { - fmt.Println(Version) - os.Exit(0) - } +func init() { + flag.BoolVar(&flagVerbose, "v", false, "Verbose output") } func main() { diff --git a/version.go b/version.go new file mode 100644 index 0000000..808a57b --- /dev/null +++ b/version.go @@ -0,0 +1,24 @@ +package main + +import ( + "flag" + "fmt" + "os" +) + +var ( + Version = "impure" + + printVersion bool +) + +func init() { + flag.BoolVar(&printVersion, "V", false, "Print version") +} + +func tryVersion() { + if printVersion { + fmt.Println(Version) + os.Exit(0) + } +}