refac: remove some duplication
This commit is contained in:
parent
24d13eb5bc
commit
9097bb4f6b
1 changed files with 8 additions and 21 deletions
21
main.go
21
main.go
|
@ -41,13 +41,15 @@ func main() {
|
||||||
app.Version(version)
|
app.Version(version)
|
||||||
app.HelpFlag.Short('h')
|
app.HelpFlag.Short('h')
|
||||||
app.VersionFlag.Short('v')
|
app.VersionFlag.Short('v')
|
||||||
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
action := kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||||
case "store":
|
|
||||||
histfile, history, err := getHistory(*histpath)
|
histfile, history, err := getHistory(*histpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "store":
|
||||||
// read copy from stdin
|
// read copy from stdin
|
||||||
var stdin []string
|
var stdin []string
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
@ -64,11 +66,6 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
case "pick":
|
case "pick":
|
||||||
_, history, err := getHistory(*histpath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
selection, err := selector(history, *maxPicker, *pickTool, "pick", *pickToolArgs)
|
selection, err := selector(history, *maxPicker, *pickTool, "pick", *pickToolArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -81,11 +78,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "restore":
|
case "restore":
|
||||||
_, history, err := getHistory(*histpath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(history) == 0 {
|
if len(history) == 0 {
|
||||||
log.Println("Nothing to restore")
|
log.Println("Nothing to restore")
|
||||||
return
|
return
|
||||||
|
@ -95,11 +87,6 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
histfile, history, err := getHistory(*histpath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove all history
|
// remove all history
|
||||||
if *clearAll {
|
if *clearAll {
|
||||||
if err := wipeAll(histfile); err != nil {
|
if err := wipeAll(histfile); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue