fortify/config: flag to print template config serialised as JSON
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
parent
2e019e48c1
commit
283bcba05b
17
config.go
17
config.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.ophivana.moe/cat/fortify/dbus"
|
"git.ophivana.moe/cat/fortify/dbus"
|
||||||
|
@ -12,6 +13,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
printTemplate bool
|
||||||
|
|
||||||
confPath string
|
confPath string
|
||||||
|
|
||||||
dbusConfigSession string
|
dbusConfigSession string
|
||||||
|
@ -27,6 +30,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
flag.BoolVar(&printTemplate, "template", false, "Print a full config template and exit")
|
||||||
|
|
||||||
// config file, disables every other flag here
|
// 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")
|
||||||
|
|
||||||
|
@ -52,6 +57,18 @@ func init() {
|
||||||
flag.StringVar(&launchMethodText, "method", "sudo", methodHelpString)
|
flag.StringVar(&launchMethodText, "method", "sudo", methodHelpString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tryTemplate() {
|
||||||
|
if printTemplate {
|
||||||
|
if s, err := json.MarshalIndent(app.Template(), "", " "); err != nil {
|
||||||
|
fatalf("cannot generate template: %v", err)
|
||||||
|
panic("unreachable")
|
||||||
|
} else {
|
||||||
|
fmt.Println(string(s))
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func loadConfig() *app.Config {
|
func loadConfig() *app.Config {
|
||||||
if confPath == "nil" {
|
if confPath == "nil" {
|
||||||
// config from flags
|
// config from flags
|
||||||
|
|
3
main.go
3
main.go
|
@ -32,9 +32,10 @@ func main() {
|
||||||
shim.Try()
|
shim.Try()
|
||||||
}
|
}
|
||||||
|
|
||||||
// version/license command early exit
|
// version/license/template command early exit
|
||||||
tryVersion()
|
tryVersion()
|
||||||
tryLicense()
|
tryLicense()
|
||||||
|
tryTemplate()
|
||||||
|
|
||||||
// state query command early exit
|
// state query command early exit
|
||||||
tryState()
|
tryState()
|
||||||
|
|
Loading…
Reference in New Issue