From ae2c0b0f795eea57728ff8541751fe643e71f804 Mon Sep 17 00:00:00 2001 From: Sahel Jalal Date: Fri, 24 Feb 2023 22:34:13 -0800 Subject: [PATCH] feat: dock/sync flag to keep downloaded sources --- cmd/dock.go | 3 ++- cmd/sync.go | 4 +++- config/sync.go | 11 ++++++++--- task/task.go | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/dock.go b/cmd/dock.go index 1b0b4f6..5786cad 100644 --- a/cmd/dock.go +++ b/cmd/dock.go @@ -26,7 +26,7 @@ Run: To force docking even if identifiers are the same, use the -f flag.`, Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - os.Exit(task.Sync(force, args)) + os.Exit(task.Sync(force, keep, args)) }, } @@ -34,4 +34,5 @@ func init() { rootCmd.AddCommand(dockCmd) dockCmd.Flags().BoolVarP(&force, "force", "f", false, "Force dock manifest") + dockCmd.Flags().BoolVarP(&keep, "keep", "k", false, "Keep downloaded files") } diff --git a/cmd/sync.go b/cmd/sync.go index e7e80f5..a6d2c29 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -8,6 +8,7 @@ import ( ) var force bool +var keep bool // syncCmd represents the sync command var syncCmd = &cobra.Command{ @@ -24,7 +25,7 @@ Sync will only update manifests with changed identifiers, to force update use the -f flag.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - os.Exit(task.Sync(force, []string{})) + os.Exit(task.Sync(force, keep, args)) }, } @@ -32,4 +33,5 @@ func init() { rootCmd.AddCommand(syncCmd) syncCmd.Flags().BoolVarP(&force, "force", "f", false, "Force sync manifests") + syncCmd.Flags().BoolVarP(&keep, "keep", "k", false, "Keep downloaded files") } diff --git a/config/sync.go b/config/sync.go index 810a203..96ff2fe 100644 --- a/config/sync.go +++ b/config/sync.go @@ -17,14 +17,14 @@ import ( ) // Sync adds a new manifest from provided sources -func (c *Config) Sync(force bool, sources []string) ([]*model.Manifest, error) { +func (c *Config) Sync(force, keep bool, sources []string) ([]*model.Manifest, error) { manifests := []*model.Manifest{} sources, err := syncPrep(sources) if err != nil { return manifests, err } - defer syncCleanup() + defer syncCleanup(keep) // Fallback to all existing manifests if no sources provided if len(sources) == 0 { @@ -82,7 +82,12 @@ func syncPrep(sources []string) ([]string, error) { return s, nil } -func syncCleanup() error { +func syncCleanup(keep bool) error { + // Persist downloads folder if requested + if keep { + return nil + } + // Remove downloads folder return os.RemoveAll(downloadsPath()) } diff --git a/task/task.go b/task/task.go index d080f6a..5174ef5 100644 --- a/task/task.go +++ b/task/task.go @@ -666,13 +666,13 @@ func Find(name string) int { return 0 } -func Sync(force bool, sources []string) int { +func Sync(force, keep bool, sources []string) int { cfg := checkConfig() if cfg == nil { return -1 } - manifests, err := cfg.Sync(force, sources) + manifests, err := cfg.Sync(force, keep, sources) if err != nil { log.Error(err) return -1