Skip to content

Commit

Permalink
Add uuidgen command to refresh manifest identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
saheljalal committed Feb 2, 2022
1 parent 97230fa commit 020eecf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
38 changes: 38 additions & 0 deletions 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)
}
26 changes: 26 additions & 0 deletions task/task.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 020eecf

Please sign in to comment.