diff --git a/cmds/updatemgr/main.go b/cmds/updatemgr/main.go index dc8487a3..a0f969f4 100644 --- a/cmds/updatemgr/main.go +++ b/cmds/updatemgr/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "os" "path/filepath" @@ -10,20 +11,27 @@ import ( "github.com/spf13/cobra" ) -var registry *updater.ResourceRegistry +var ( + registry *updater.ResourceRegistry + distDir string +) var rootCmd = &cobra.Command{ Use: "updatemgr", Short: "A simple tool to assist in the update and release process", - Args: cobra.ExactArgs(1), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - absPath, err := filepath.Abs(args[0]) + // Check if the distribution directory exists. + absDistPath, err := filepath.Abs(distDir) if err != nil { - return err + return fmt.Errorf("failed to get absolute path of distribution directory: %w", err) + } + _, err = os.Stat(absDistPath) + if err != nil { + return fmt.Errorf("failed to access distribution directory: %w", err) } registry = &updater.ResourceRegistry{} - err = registry.Initialize(utils.NewDirStructure(absPath, 0o755)) + err = registry.Initialize(utils.NewDirStructure(absDistPath, 0o755)) if err != nil { return err } @@ -55,6 +63,11 @@ var rootCmd = &cobra.Command{ SilenceUsage: true, } +func init() { + flags := rootCmd.PersistentFlags() + flags.StringVar(&distDir, "dist-dir", "dist", "Set the distribution directory. Falls back to ./dist if available.") +} + func main() { if err := rootCmd.Execute(); err != nil { os.Exit(1) diff --git a/cmds/updatemgr/purge.go b/cmds/updatemgr/purge.go index 6548adb7..cfdf3711 100644 --- a/cmds/updatemgr/purge.go +++ b/cmds/updatemgr/purge.go @@ -15,7 +15,6 @@ func init() { var purgeCmd = &cobra.Command{ Use: "purge", Short: "Remove old resource versions that are superseded by at least three versions", - Args: cobra.ExactArgs(1), RunE: purge, } diff --git a/cmds/updatemgr/update.go b/cmds/updatemgr/release.go similarity index 87% rename from cmds/updatemgr/update.go rename to cmds/updatemgr/release.go index 47a6429f..32a296a8 100644 --- a/cmds/updatemgr/update.go +++ b/cmds/updatemgr/release.go @@ -11,17 +11,16 @@ import ( ) func init() { - rootCmd.AddCommand(updateCmd) + rootCmd.AddCommand(releaseCmd) } -var updateCmd = &cobra.Command{ - Use: "update", - Short: "Update scans the specified directory and registry the index and symlink structure", - Args: cobra.ExactArgs(1), - RunE: update, +var releaseCmd = &cobra.Command{ + Use: "release", + Short: "Release scans the distribution directory and creates registry indexes and the symlink structure", + RunE: release, } -func update(cmd *cobra.Command, args []string) error { +func release(cmd *cobra.Command, args []string) error { // Set stable and beta to latest version. updateToLatestVersion(true, true) diff --git a/cmds/updatemgr/scan.go b/cmds/updatemgr/scan.go index 47ef40cd..afcd489c 100644 --- a/cmds/updatemgr/scan.go +++ b/cmds/updatemgr/scan.go @@ -14,7 +14,6 @@ func init() { var scanCmd = &cobra.Command{ Use: "scan", Short: "Scan the specified directory and print the result", - Args: cobra.ExactArgs(1), RunE: scan, } diff --git a/cmds/updatemgr/staging.go b/cmds/updatemgr/staging.go index 24b7a8a7..63398b9b 100644 --- a/cmds/updatemgr/staging.go +++ b/cmds/updatemgr/staging.go @@ -22,7 +22,6 @@ func init() { var stageCmd = &cobra.Command{ Use: "stage", Short: "Stage scans the specified directory and loads the indexes - it then creates a staging index with all files newer than the stable and beta indexes", - Args: cobra.ExactArgs(1), RunE: stage, }