diff --git a/cmd/genconfig.go b/cmd/genconfig.go new file mode 100644 index 0000000..0237275 --- /dev/null +++ b/cmd/genconfig.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "gcs-backup/pkg/config" + "log" + "os" + + "git.trj.tw/golang/argparse" + confloader "git.trj.tw/golang/config-loader" + "gopkg.in/yaml.v2" +) + +func main() { + fmt.Println("generate config file") + + confPath := "" + + parser := argparse.New() + parser.StringVar(&confPath, "", "o", "output", "config output path", &argparse.Option{Require: true}) + + if err := parser.Parse(os.Args); err != nil { + log.Fatal(err) + } + + file, err := os.Create(confPath) + if err != nil { + log.Fatal(err) + } + defer file.Close() + + conf := &config.Config{} + + if err := confloader.Load(conf, nil); err != nil { + log.Fatal(err) + } + + b, err := yaml.Marshal(conf) + if err != nil { + log.Fatal(err) + } + + if _, err := file.Write(b); err != nil { + log.Fatal(err) + } +}