mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Move the dist dir to a flag and auto-detect it
Also, rename update to release
This commit is contained in:
parent
3d2cbdd4e6
commit
47aec76a45
5 changed files with 24 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue