Skip to content

Commit

Permalink
Add command to delete lockfile (closes #66)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeemster committed Sep 22, 2016
1 parent b9d52c9 commit 4b5e5a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
log.Fatalf("Error making lock: %s", lockErr2.Error())
}
}

statuses := run.Run(*pb, sp, options.fromStep, options.dryRun)
code, message := review(statuses)

Expand Down Expand Up @@ -117,6 +117,23 @@ func processFlags() Options {
}
}

if options.deleteLock != "" {
lockFile, lockErr := LockFileFromOptions(options)
if lockErr != nil {
unlockErr := lockFile.Unlock()
if unlockErr != nil {
log.Printf("Error: %s found but could not delete: %s", lockFile.Path, unlockErr.Error())
os.Exit(1)
} else {
log.Printf("Success: %s found and deleted", lockFile.Path)
os.Exit(0)
}
} else {
log.Printf("Error: %s does not exist, nothing to delete", lockFile.Path)
os.Exit(1)
}
}

if options.playbook == "" {
fmt.Println("required flag not defined: -playbook")
os.Exit(2)
Expand Down Expand Up @@ -175,6 +192,9 @@ func LockFileFromOptions(options Options) (*LockFile, error) {
} else if options.checkLock != "" {
lockPath = options.checkLock
isSoftLock = false
} else if options.deleteLock != "" {
lockPath = options.deleteLock
isSoftLock = false
} else {
// no-op
return nil, nil
Expand Down
24 changes: 13 additions & 11 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ func (i *CLIVariables) Set(value string) error {
}

type Options struct {
help bool
version bool
playbook string
sqlroot string
fromStep string
dryRun bool
consul string
lock string
softLock string
checkLock string
variables CLIVariables
help bool
version bool
playbook string
sqlroot string
fromStep string
dryRun bool
consul string
lock string
softLock string
checkLock string
deleteLock string
variables CLIVariables
}

func NewOptions() Options {
Expand All @@ -67,6 +68,7 @@ func (o *Options) GetFlagSet() *flag.FlagSet {
fs.StringVar(&(o.lock), "lock", "", "Optional argument which checks and sets a lockfile to ensure this run is a singleton. Deletes lock on run completing successfully")
fs.StringVar(&(o.softLock), "softLock", "", "Optional argument, like '-lock' but the lockfile will be deleted even if the run fails")
fs.StringVar(&(o.checkLock), "checkLock", "", "Checks whether the lockfile already exists")
fs.StringVar(&(o.deleteLock), "deleteLock", "", "Will attempt to delete a lockfile if it exists")
// TODO: add format flag if/when we support TOML

return fs
Expand Down

0 comments on commit 4b5e5a3

Please sign in to comment.