break
}
- cfg, err := LoadConfig(args[1])
+ mainFetch(args[1])
+ return
+
+ case "convert":
+ if len(args) != 4 {
+ break
+ }
+
+ mainConvert(args[1], args[2], args[3])
+ return
+ }
+
+ flag.Usage()
+ os.Exit(1)
+}
+
+func mainFetch(cfgPath string) {
+ cfg, err := LoadConfig(cfgPath)
if err != nil {
log.Fatal(err)
}
if err != nil {
log.Fatal(err)
}
- return
-
- case "convert":
- if len(args) != 4 {
- break
- }
+}
+func mainConvert(typ, srcPath, dstPath string) {
var t FileType
- err := t.UnmarshalText([]byte(args[1]))
+ err := t.UnmarshalText([]byte(typ))
if err != nil {
log.Fatal(err)
}
- src, err := ioutil.ReadFile(args[2])
+ src, err := ioutil.ReadFile(srcPath)
if err != nil {
log.Fatal(err)
}
}
// We must create the file first or deployFile() will abort
- f, err := os.Create(args[3])
+ f, err := os.Create(dstPath)
if err != nil {
log.Fatal(err)
}
err = deployFile(&File{
Type: t,
- Url: args[2],
- Path: args[3],
+ Url: srcPath,
+ Path: dstPath,
body: x.Bytes(),
})
if err != nil {
log.Fatal(err)
}
- return
- }
-
- flag.Usage()
- os.Exit(1)
}