From d2575b670835fd19f7a67e5eee476a46eb9822e5 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sat, 12 Oct 2024 01:28:22 +0900 Subject: fortify: move flag handling to separate files Signed-off-by: Ophestra Umiker --- config.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ flag.go | 56 -------------------------------------------------------- main.go | 9 +++------ version.go | 24 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 62 deletions(-) create mode 100644 config.go delete mode 100644 flag.go create mode 100644 version.go diff --git a/config.go b/config.go new file mode 100644 index 00000000..c5a58979 --- /dev/null +++ b/config.go @@ -0,0 +1,51 @@ +package main + +import ( + "flag" + + "git.ophivana.moe/cat/fortify/internal" +) + +var ( + confPath string + + dbusConfigSession string + dbusConfigSystem string + dbusVerbose bool + dbusID string + mpris bool + + userName string + mustWayland bool + mustX bool + mustDBus bool + mustPulse bool + + launchMethodText string +) + +func init() { + // 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") + flag.StringVar(&dbusConfigSystem, "dbus-system", "nil", "Path to system D-Bus proxy config file, or \"nil\" to disable") + flag.BoolVar(&dbusVerbose, "dbus-log", false, "Enable logging in the D-Bus proxy") + 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") +} + +func init() { + methodHelpString := "Method of launching the child process, can be one of \"sudo\"" + if internal.SdBootedV { + methodHelpString += ", \"systemd\"" + } + + flag.StringVar(&launchMethodText, "method", "sudo", methodHelpString) +} diff --git a/flag.go b/flag.go deleted file mode 100644 index 673601d5..00000000 --- a/flag.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "flag" - - "git.ophivana.moe/cat/fortify/internal" -) - -var ( - userName string - confPath string - - dbusConfigSession string - dbusConfigSystem string - dbusVerbose bool - dbusID string - mpris bool - - 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") - 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") - flag.StringVar(&dbusConfigSystem, "dbus-system", "nil", "Path to system D-Bus proxy config file, or \"nil\" to disable") - flag.BoolVar(&dbusVerbose, "dbus-log", false, "Enable logging in the D-Bus proxy") - 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.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() { - methodHelpString := "Method of launching the child process, can be one of \"sudo\"" - if internal.SdBootedV { - methodHelpString += ", \"systemd\"" - } - - flag.StringVar(&launchMethodText, "method", "sudo", methodHelpString) -} diff --git a/main.go b/main.go index c30bfcaf..45fbd216 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 00000000..808a57b9 --- /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) + } +} -- cgit v1.3.1