Skip to content

Commit

Permalink
Merge pull request #49 from ivanilves/exit-to-the-parent-dir
Browse files Browse the repository at this point in the history
feat: exit to the parent directory on CTRL-C
  • Loading branch information
ivanilves authored May 13, 2023
2 parents f4743ad + 839d01d commit 0275d26
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmd/travelgrunt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func buildMenuFromTree(t tree.Tree) string {

if err != nil {
if err.Error() == "^C" {
os.Exit(1)
return parentID
}

log.Fatalf("failed to build menu: %s", err.Error())
Expand All @@ -73,6 +73,16 @@ func buildMenuFromTree(t tree.Tree) string {
return selected
}

func getEntryPath(entries map[string]string, selected, rootPath string) (path string) {
path = entries[selected]

if path == "" {
path = rootPath + "/" + selected
}

return path
}

func main() {
flag.Usage = usage
flag.Parse()
Expand Down Expand Up @@ -114,7 +124,9 @@ func main() {
)

if outFile != "" {
writeFileAndExit(outFile, entries[selected])
path := getEntryPath(entries, selected, rootPath)

writeFileAndExit(outFile, path)
}

log.Fatal("Please configure shell aliases as described: https://github.com/ivanilves/travelgrunt#shell-aliases")
Expand Down

0 comments on commit 0275d26

Please sign in to comment.