Skip to content

Commit

Permalink
feat: dock/sync flag to keep downloaded sources
Browse files Browse the repository at this point in the history
  • Loading branch information
saheljalal committed Feb 25, 2023
1 parent 045d5d8 commit ae2c0b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/dock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ 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))
},
}

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")
}
4 changes: 3 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var force bool
var keep bool

// syncCmd represents the sync command
var syncCmd = &cobra.Command{
Expand All @@ -24,12 +25,13 @@ 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))
},
}

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")
}
11 changes: 8 additions & 3 deletions config/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae2c0b0

Please sign in to comment.