diff --git a/goatherd.go b/goatherd.go index a5da09a4eada4a20607e435aabf4cf77e677c229..c7e0dbe4a56eda790afd6aa3abba39e49a882614 100644 --- a/goatherd.go +++ b/goatherd.go @@ -34,6 +34,9 @@ func (d *duration) UnmarshalJSON(b []byte) (err error) { return } +func (d duration) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, d.String())), nil +} var cfg struct { @@ -361,6 +364,7 @@ func main() { flag_add_user := flag.String("add-user", "", "Add new user to the database. If '-' read name from stdin.") flag_secret := flag.String("secret", "-", "Secret for the new user. If '-' read from stdin.") flag_serve := flag.Bool("serve", false, "Start daemon.") + flag_dump_config := flag.Bool("dump-config", false, "Dump the effective config to stdout.") // also settable in config file flag.StringVar(&cfg.Db_url, "db-url", ":memory:", "URL used to connect to the database.") @@ -390,6 +394,13 @@ func main() { // default action is to serve, but not if one of the other actions is given serve_default := true + if *flag_dump_config { + serve_default = false + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", "\t") + err_fatal(enc.Encode(cfg)) + } + if *flag_init_db { serve_default = false create_table(db)