mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29: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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -10,20 +11,27 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var registry *updater.ResourceRegistry
|
var (
|
||||||
|
registry *updater.ResourceRegistry
|
||||||
|
distDir string
|
||||||
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "updatemgr",
|
Use: "updatemgr",
|
||||||
Short: "A simple tool to assist in the update and release process",
|
Short: "A simple tool to assist in the update and release process",
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
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 {
|
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{}
|
registry = &updater.ResourceRegistry{}
|
||||||
err = registry.Initialize(utils.NewDirStructure(absPath, 0o755))
|
err = registry.Initialize(utils.NewDirStructure(absDistPath, 0o755))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -55,6 +63,11 @@ var rootCmd = &cobra.Command{
|
||||||
SilenceUsage: true,
|
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() {
|
func main() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -15,7 +15,6 @@ func init() {
|
||||||
var purgeCmd = &cobra.Command{
|
var purgeCmd = &cobra.Command{
|
||||||
Use: "purge",
|
Use: "purge",
|
||||||
Short: "Remove old resource versions that are superseded by at least three versions",
|
Short: "Remove old resource versions that are superseded by at least three versions",
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
RunE: purge,
|
RunE: purge,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,17 +11,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(updateCmd)
|
rootCmd.AddCommand(releaseCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateCmd = &cobra.Command{
|
var releaseCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "release",
|
||||||
Short: "Update scans the specified directory and registry the index and symlink structure",
|
Short: "Release scans the distribution directory and creates registry indexes and the symlink structure",
|
||||||
Args: cobra.ExactArgs(1),
|
RunE: release,
|
||||||
RunE: update,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(cmd *cobra.Command, args []string) error {
|
func release(cmd *cobra.Command, args []string) error {
|
||||||
// Set stable and beta to latest version.
|
// Set stable and beta to latest version.
|
||||||
updateToLatestVersion(true, true)
|
updateToLatestVersion(true, true)
|
||||||
|
|
|
@ -14,7 +14,6 @@ func init() {
|
||||||
var scanCmd = &cobra.Command{
|
var scanCmd = &cobra.Command{
|
||||||
Use: "scan",
|
Use: "scan",
|
||||||
Short: "Scan the specified directory and print the result",
|
Short: "Scan the specified directory and print the result",
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
RunE: scan,
|
RunE: scan,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ func init() {
|
||||||
var stageCmd = &cobra.Command{
|
var stageCmd = &cobra.Command{
|
||||||
Use: "stage",
|
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",
|
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,
|
RunE: stage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue