add overwrite flag (#913)

* add storagenode setup --overwrite flag
* exit setup with error code
This commit is contained in:
littleskunk 2018-12-20 14:27:51 +01:00 committed by GitHub
parent 0a717ac4fe
commit e1c3f11cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -56,8 +56,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
valid, err := fpath.IsValidSetupDir(setupDir)
if !setupCfg.Overwrite && !valid {
fmt.Printf("captplanet configuration already exists (%v). rerun with --overwrite\n", setupDir)
return nil
return fmt.Errorf("captplanet configuration already exists (%v). Rerun with --overwrite", setupDir)
} else if setupCfg.Overwrite && err == nil {
fmt.Println("overwriting existing captplanet config")
err = os.RemoveAll(setupDir)

View File

@ -149,8 +149,7 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
valid, err := fpath.IsValidSetupDir(setupDir)
if !setupCfg.Overwrite && !valid {
fmt.Printf("satellite configuration already exists (%v). rerun with --overwrite\n", setupDir)
return nil
return fmt.Errorf("satellite configuration already exists (%v). Rerun with --overwrite", setupDir)
} else if setupCfg.Overwrite && err == nil {
fmt.Println("overwriting existing satellite config")
err = os.RemoveAll(setupDir)

View File

@ -55,8 +55,9 @@ var (
Storage psserver.Config
}
setupCfg struct {
CA provider.CASetupConfig
Identity provider.IdentitySetupConfig
CA provider.CASetupConfig
Identity provider.IdentitySetupConfig
Overwrite bool `default:"false" help:"whether to overwrite pre-existing configuration files"`
}
diagCfg struct {
}
@ -112,6 +113,17 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
return err
}
valid, err := fpath.IsValidSetupDir(setupDir)
if !setupCfg.Overwrite && !valid {
return fmt.Errorf("storagenode configuration already exists (%v). Rerun with --overwrite", setupDir)
} else if setupCfg.Overwrite && err == nil {
fmt.Println("overwriting existing satellite config")
err = os.RemoveAll(setupDir)
if err != nil {
return err
}
}
err = os.MkdirAll(setupDir, 0700)
if err != nil {
return err