diff --git a/cmd/uuidgen.go b/cmd/uuidgen.go new file mode 100644 index 0000000..474d1d6 --- /dev/null +++ b/cmd/uuidgen.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "os" + + "github.com/pokanop/nostromo/task" + "github.com/spf13/cobra" +) + +// uuidgenCmd represents the uuidgen command +var uuidgenCmd = &cobra.Command{ + Use: "uuidgen [name]", + Short: "Generate a new unique id for a manifest", + Long: `Generate a new unique id for a manifest. + +nostromo uses a uuid to determine if a manifest is unique or not. +When using sync to get new manifests, nostromo will only apply the +changes if it detects a different identifier. + +This command allows regenerating the uuid to allow for publishing +and pulling updated manifests. Note that using standard nostromo +commands automatically updates the identifier. This command can be +used if manual updates were made to a manifest. + +Omitting the name of the manifest will apply to the core manifest.`, + Args: cobra.MaximumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + var name string + if len(args) > 0 { + name = args[0] + } + os.Exit(task.RegenerateID(name)) + }, +} + +func init() { + rootCmd.AddCommand(uuidgenCmd) +} diff --git a/task/task.go b/task/task.go index 664a94c..e917c6d 100644 --- a/task/task.go +++ b/task/task.go @@ -12,6 +12,7 @@ import ( "github.com/pokanop/nostromo/prompt" "github.com/pokanop/nostromo/shell" "github.com/pokanop/nostromo/stringutil" + "github.com/pokanop/nostromo/version" "github.com/shivamMg/ppds/tree" "github.com/spf13/cobra" ) @@ -592,6 +593,31 @@ func Detach(name string, keyPaths []string, targetKeyPath, description string, k return 0 } +func RegenerateID(name string) int { + cfg := checkConfig() + var m *model.Manifest + if len(name) > 0 { + m = cfg.Spaceport().FindManifest(name) + if m == nil { + log.Errorf("no manifest named %s exists\n", name) + return -1 + } + } else { + m = cfg.Spaceport().CoreManifest() + } + + v := version.NewInfo(m.Version.SemVer, m.Version.GitCommit, m.Version.BuildDate) + m.Version.Update(v) + + err := config.SaveManifest(m, m.IsCore()) + if err != nil { + log.Error(err) + return -1 + } + + return 0 +} + func checkConfigQuiet() *config.Config { return checkConfigCommon(true) }