Rather than loading most of the time in main() (and failing if it fails),
and then also loading the config in "repo init" (and tolerating its absence),
always attempt to load the config, and only fail if we end up missing bits of
information that we need.
This will set the stage for unifying the configuration and the
command-line options.
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
var err error
var xsanum int
- loadConfig := true
loadGlobal := false
loadXSA := false
checkXSARepos := true
switch cmd {
case "init":
main = MainRepoInit
- loadConfig = false
case "update":
main = MainRepoUpdate
case "x":
}
}
- if loadConfig {
- if err := G.config.Tool.Load(); err != nil {
- fmt.Printf("Error finding config: %v\n", err)
- return 1
- }
+ // Always load the config
+ if err := G.config.Tool.Load(); err != nil && !os.IsNotExist(err) {
+ fmt.Printf("Error loading config: %v\n", err)
+ return 1
}
if loadGlobal {
}
// Not saved
rootDir string
+ loaded bool
}
const ConfigFileName = ".xsatool"
}
err = json.Unmarshal(b, tc)
+
+ if err == nil {
+ tc.loaded = true
+ }
+
return
}
return 1
}
- if err := G.config.Tool.Load(); err != nil {
- if os.IsNotExist(err) {
- fmt.Printf("Initializing new tool config")
- G.config.Tool.Init()
- } else {
- fmt.Printf("Error opening config file: %v\n", err)
- return 1
- }
+ if !G.config.Tool.loaded {
+ fmt.Printf("Initializing new tool config\n")
+ G.config.Tool.Init()
} else {
fmt.Printf("Using existing tool config in %s\n", G.config.Tool.rootDir)
}