Move the dist dir to a flag and auto-detect it

Also, rename update to release
This commit is contained in:
Daniel
2020-12-22 13:23:05 +01:00
parent 3d2cbdd4e6
commit 47aec76a45
5 changed files with 24 additions and 15 deletions

View File

@@ -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)