Skip to content

Commit

Permalink
Fix 'recent' command
Browse files Browse the repository at this point in the history
* Fix off by 1 error returning results
* Rename option to '-n|--number'
  • Loading branch information
msp301 committed Oct 12, 2023
1 parent ceb82b7 commit d5b1e97
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/recent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var recentCmd = &cobra.Command{
Use: "recent",
Short: "Output notes recently worked on",
Run: func(cmd *cobra.Command, args []string) {
maxResults := viper.GetInt("recentNumber")
maxResults := viper.GetInt("number")
results := 0
book().Notes.WalkBackwards(func(vertex graph.Vertex, _ int) bool {
if results > maxResults {
if results >= maxResults {
return false
}
switch val := vertex.Properties["Value"].(type) {
Expand All @@ -29,7 +29,7 @@ var recentCmd = &cobra.Command{
}

func init() {
recentCmd.PersistentFlags().Int("recentNumber", 10, "Number of results to return")
viper.BindPFlag("recentNumber", recentCmd.PersistentFlags().Lookup("recentNumber"))
recentCmd.PersistentFlags().IntP("number", "n", 10, "Number of results to return")
viper.BindPFlag("number", recentCmd.PersistentFlags().Lookup("number"))
rootCmd.AddCommand(recentCmd)
}

0 comments on commit d5b1e97

Please sign in to comment.