Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --prune option #5

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (cli *CLI) Run(args []string) int {
originPath string
deployPath string
prunedDirs bool
prune bool
skipPrune bool
version bool
isDebug bool
Expand All @@ -47,6 +48,7 @@ func (cli *CLI) Run(args []string) int {
flags.BoolVar(&isRollback, "rollback", false, "")
flags.BoolVar(&isRollback, "r", false, "")
flags.BoolVar(&prunedDirs, "pruned-dirs", false, "")
flags.BoolVar(&prune, "prune", false, "")
flags.BoolVar(&skipPrune, "skip-prune", false, "")
flags.BoolVar(&version, "version", false, "")
flags.BoolVar(&version, "v", false, "")
Expand Down Expand Up @@ -86,6 +88,24 @@ func (cli *CLI) Run(args []string) int {
for _, dir := range dirs {
fmt.Printf("%v\n", dir)
}
} else if prune {
arg := flags.Args()
if len(arg) < 1 {
fmt.Fprintf(cli.errStream, "Too few arguments (%d!=1): must specify one arguments", len(arg))
return 11
}

deployPath = filepath.Clean(arg[0])

r := release.NewRelease(deployPath)
if err := r.Cleanup(keep); err != nil {
if isDebug {
fmt.Fprintf(cli.errStream, "%+v\n", err)
} else {
fmt.Fprintf(cli.errStream, "%s\n", errors.Cause(err))
}
return -1
}
} else if isRollback {
// rollback mode
arg := flags.Args()
Expand Down Expand Up @@ -142,6 +162,8 @@ Options:

--pruned-dirs Show directories pruned (Optional)

--prune Just cleanup old directories

--skip-prune Do not cleanup old directories (the --keep option is ignored)

--debug, -d Run with debug print
Expand Down