fortify: move flag handling to separate files

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-10-12 01:28:22 +09:00
parent 8d82446d97
commit d2575b6708
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
3 changed files with 30 additions and 14 deletions

View File

@ -7,7 +7,6 @@ import (
) )
var ( var (
userName string
confPath string confPath string
dbusConfigSession string dbusConfigSession string
@ -16,19 +15,17 @@ var (
dbusID string dbusID string
mpris bool mpris bool
userName string
mustWayland bool mustWayland bool
mustX bool mustX bool
mustDBus bool mustDBus bool
mustPulse bool mustPulse bool
flagVerbose bool
printVersion bool
launchMethodText string launchMethodText string
) )
func init() { 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(&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(&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.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(&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(&mustWayland, "wayland", false, "Share Wayland socket")
flag.BoolVar(&mustX, "X", false, "Share X11 socket and allow connection") flag.BoolVar(&mustX, "X", false, "Share X11 socket and allow connection")
flag.BoolVar(&mustDBus, "dbus", false, "Proxy D-Bus connection") flag.BoolVar(&mustDBus, "dbus", false, "Proxy D-Bus connection")
flag.BoolVar(&mustPulse, "pulse", false, "Share PulseAudio socket and cookie") 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() { func init() {

View File

@ -16,14 +16,11 @@ import (
) )
var ( var (
Version = "impure" flagVerbose bool
) )
func tryVersion() { func init() {
if printVersion { flag.BoolVar(&flagVerbose, "v", false, "Verbose output")
fmt.Println(Version)
os.Exit(0)
}
} }
func main() { func main() {

24
version.go Normal file
View File

@ -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)
}
}