fortify/config: flag to print template config serialised as JSON

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-10-12 19:46:40 +09:00
parent 2e019e48c1
commit 283bcba05b
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 19 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"git.ophivana.moe/cat/fortify/dbus"
@ -12,6 +13,8 @@ import (
)
var (
printTemplate bool
confPath string
dbusConfigSession string
@ -27,6 +30,8 @@ var (
)
func init() {
flag.BoolVar(&printTemplate, "template", false, "Print a full config template and exit")
// config file, disables every other flag here
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)
}
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 {
if confPath == "nil" {
// config from flags

View File

@ -32,9 +32,10 @@ func main() {
shim.Try()
}
// version/license command early exit
// version/license/template command early exit
tryVersion()
tryLicense()
tryTemplate()
// state query command early exit
tryState()