command/init: Only initialize a blank state with remote
This commit is contained in:
parent
9168a0f1ce
commit
6e7cffd60b
|
@ -52,14 +52,6 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the remote configuration
|
|
||||||
if !remoteConf.Empty() {
|
|
||||||
if err := remote.ValidateConfig(&remoteConf); err != nil {
|
|
||||||
c.Ui.Error(fmt.Sprintf("%s", err))
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
source := args[0]
|
source := args[0]
|
||||||
|
|
||||||
// Get our pwd since we need it
|
// Get our pwd since we need it
|
||||||
|
@ -99,20 +91,35 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
|
|
||||||
// Handle remote state if configured
|
// Handle remote state if configured
|
||||||
if !remoteConf.Empty() {
|
if !remoteConf.Empty() {
|
||||||
change, err := remote.RefreshState(&remoteConf)
|
// Ensure remote state is not already enabled
|
||||||
|
haveLocal, err := remote.HaveLocalState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf("Failed to check for local state: %v", err))
|
||||||
"Failed to refresh from remote state: %v", err))
|
return 1
|
||||||
|
}
|
||||||
|
if haveLocal {
|
||||||
|
c.Ui.Error("Remote state is already enabled. Aborting.")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the change that took place
|
// Check if we have the non-managed state file
|
||||||
c.Ui.Output(fmt.Sprintf("%s", change))
|
haveNonManaged, err := remote.ExistsFile(DefaultStateFilename)
|
||||||
|
if err != nil {
|
||||||
// Use an error exit code if the update was not a success
|
c.Ui.Error(fmt.Sprintf("Failed to check for state file: %v", err))
|
||||||
if !change.SuccessfulPull() {
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
if haveNonManaged {
|
||||||
|
c.Ui.Error(fmt.Sprintf("Existing state file '%s' found. Aborting.",
|
||||||
|
DefaultStateFilename))
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize a blank state file with remote enabled
|
||||||
|
remoteCmd := &RemoteCommand{
|
||||||
|
Meta: c.Meta,
|
||||||
|
remoteConf: remoteConf,
|
||||||
|
}
|
||||||
|
return remoteCmd.initBlankState()
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (c *RemoteCommand) Run(args []string) int {
|
||||||
cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError)
|
||||||
cmdFlags.BoolVar(&c.conf.disableRemote, "disable", false, "")
|
cmdFlags.BoolVar(&c.conf.disableRemote, "disable", false, "")
|
||||||
cmdFlags.BoolVar(&c.conf.pullOnDisable, "pull", true, "")
|
cmdFlags.BoolVar(&c.conf.pullOnDisable, "pull", true, "")
|
||||||
cmdFlags.StringVar(&c.conf.statePath, "state", "", "path")
|
cmdFlags.StringVar(&c.conf.statePath, "state", DefaultStateFilename, "path")
|
||||||
cmdFlags.StringVar(&c.conf.backupPath, "backup", "", "path")
|
cmdFlags.StringVar(&c.conf.backupPath, "backup", "", "path")
|
||||||
cmdFlags.StringVar(&c.remoteConf.AuthToken, "auth", "", "")
|
cmdFlags.StringVar(&c.remoteConf.AuthToken, "auth", "", "")
|
||||||
cmdFlags.StringVar(&c.remoteConf.Name, "name", "", "")
|
cmdFlags.StringVar(&c.remoteConf.Name, "name", "", "")
|
||||||
|
|
Loading…
Reference in New Issue