[feat] add bin command

This commit is contained in:
Jay 2020-09-03 07:39:03 +00:00
parent 63e28b6020
commit 26f5ae7677
1 changed files with 46 additions and 0 deletions

46
cmd/genconfig.go Normal file
View File

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