Re-add the ability to view or edit the latest zet
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
5a64827825
commit
df9fa52c21
3 changed files with 37 additions and 10 deletions
21
cmd/edit.go
21
cmd/edit.go
|
@ -14,18 +14,29 @@ var editCmd = &cobra.Command{
|
||||||
Use: "edit",
|
Use: "edit",
|
||||||
Aliases: []string{"e"},
|
Aliases: []string{"e"},
|
||||||
Short: "Edit a specific zettel",
|
Short: "Edit a specific zettel",
|
||||||
Long: `zet edit|e ID`,
|
Long: `zet edit|e ID
|
||||||
|
zet edit|e latest
|
||||||
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
fmt.Println("Error: No id provided")
|
fmt.Println("Error: No id provided")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
idInt, err := strconv.Atoi(args[0])
|
var id int
|
||||||
if err != nil {
|
|
||||||
os.Exit(1)
|
if args[0] == "latest" {
|
||||||
|
id = lib.GetLatestZet()
|
||||||
|
} else {
|
||||||
|
i, err := strconv.Atoi(args[0])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
id = i
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.EditZet(idInt)
|
lib.EditZet(id)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
20
cmd/view.go
20
cmd/view.go
|
@ -14,19 +14,29 @@ var viewCmd = &cobra.Command{
|
||||||
Use: "view",
|
Use: "view",
|
||||||
Aliases: []string{"v"},
|
Aliases: []string{"v"},
|
||||||
Short: "View a specific zettel",
|
Short: "View a specific zettel",
|
||||||
Long: `zet view|v ID`,
|
Long: `zet view|v ID
|
||||||
|
zet view|v latest
|
||||||
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
fmt.Println("Error: No id provided")
|
fmt.Println("Error: No id provided")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
idInt, err := strconv.Atoi(args[0])
|
var id int
|
||||||
|
|
||||||
if err != nil {
|
if args[0] == "latest" {
|
||||||
os.Exit(1)
|
id = lib.GetLatestZet()
|
||||||
|
} else {
|
||||||
|
i, err := strconv.Atoi(args[0])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
id = i
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(lib.ViewZet(idInt))
|
fmt.Println(lib.ViewZet(id))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,12 @@ func GetAllZets() []int {
|
||||||
return sorted
|
return sorted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLatestZet() int {
|
||||||
|
z := GetAllZets()
|
||||||
|
|
||||||
|
return z[len(z)-1]
|
||||||
|
}
|
||||||
|
|
||||||
func SearchZets(query string) []int {
|
func SearchZets(query string) []int {
|
||||||
zets, err := execGitCommand("grep", "-i", "--name-only", "--word-regex", query)
|
zets, err := execGitCommand("grep", "-i", "--name-only", "--word-regex", query)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue