Skip to content

Commit

Permalink
Merge pull request #24 from danielmichaels/replace-scan-with-prompt
Browse files Browse the repository at this point in the history
`zet edit <tgt>` prompt and bug fixes
  • Loading branch information
danielmichaels authored May 30, 2022
2 parents 3887a47 + e8af5b4 commit 708e9e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Cmd = &Z.Cmd{

Name: `zet`,
Summary: `zettelkasten commander`,
Version: `v0.2.0`,
Version: `v0.2.1`,
Copyright: `Copyright 2022 Daniel Michaels`,
License: `Apache-2.0`,
Site: `danielms.site`,
Expand Down
26 changes: 9 additions & 17 deletions edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
Z "github.com/rwxrob/bonzai/z"
"github.com/rwxrob/help"
"github.com/rwxrob/term"
"os"
"path/filepath"
"regexp"
"strconv"
"text/template"
)

Expand Down Expand Up @@ -122,7 +124,6 @@ func (z *Zet) openZetForEdit(zet string) error {
}
func (z *Zet) edit(args ...string) error {
zet, err := z.searchScanner(args[0])
println(zet)
fmt.Println(z)
err = z.openZetForEdit(zet)
if err != nil {
Expand Down Expand Up @@ -163,27 +164,18 @@ func (z *Zet) searchScanner(args ...string) (string, error) {
}
if len(ff) == 0 {
fmt.Printf("No entries found for %q\n", args[0])
return "", err
os.Exit(0)
}
for _, k := range ff {
fmt.Printf("%d) %s %s\n", k.Index, k.Id, k.Title)
}
var s int
fmt.Printf("#> ")
_, err = fmt.Scanln(&s)
if err != nil {
switch err.Error() {
case "unexpected newline":
fmt.Println("Did not enter a value. Exiting.")
return "", err
case "expected integer":
fmt.Println("Must enter an integer")
return "", err
default:
return "", err
}
prompt := term.Prompt("#> ")
if prompt == "" {
fmt.Println("exiting. did not provide valid entry.")
os.Exit(0)
}

s, _ := strconv.Atoi(prompt)
var zet string
for _, k := range ff {
if s == k.Index {
Expand All @@ -192,7 +184,7 @@ func (z *Zet) searchScanner(args ...string) (string, error) {
}
if zet == "" {
fmt.Println("Key entered does not match, or zet could not be found")
return "", nil
os.Exit(0)
}

return zet, nil
Expand Down
21 changes: 4 additions & 17 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
Z "github.com/rwxrob/bonzai/z"
"github.com/rwxrob/help"
"github.com/rwxrob/term"
"os"
"strings"
)

var GitCmd = &Z.Cmd{
Expand Down Expand Up @@ -38,24 +38,11 @@ var gitPull = &Z.Cmd{
// scanAndCommit checks that the user wants to commit their work to the VCS
// and pushes the commit if they accept.
func (z *Zet) scanAndCommit(zet string) error {
var r string
fmt.Printf("Commit? y/N ")
_, err := fmt.Scanln(&r)
if err != nil {
// <Enter> will return the following error, so we mark it as "N".
if err.Error() != "unexpected newline" {
return err
}
r = "N"
}
r = strings.TrimSpace(r)
r = strings.ToLower(r)

if r != "y" {
if term.Prompt("Commit? (y/N) ") != "y" {
fmt.Printf("%q not commited but modified\n", zet)
return nil
os.Exit(0)
}
err = z.PullAddCommitPush()
err := z.PullAddCommitPush()
if err != nil {
return err
}
Expand Down

0 comments on commit 708e9e2

Please sign in to comment.