Skip to content

Commit

Permalink
feat: add --archive flag in ls and search cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanchapai committed Mar 10, 2024
1 parent dec1b1a commit e5997c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import (
"github.com/spf13/cobra"
)

var listArchived bool

// lsCmd represents the ls command
var lsCmd = &cobra.Command{
Use: "ls",
Short: "list all events",
Run: func(_ *cobra.Command, _ []string) {
allEvents := eventsFromEventsFile(ereActiveEventsFileName)
var fileName string
if listArchived {
fileName = ereArchivedEventsFileName
} else {
fileName = ereActiveEventsFileName
}
allEvents := eventsFromEventsFile(fileName)
lsTable(allEvents)
},
}
Expand Down Expand Up @@ -45,4 +53,5 @@ func lsTable(events []Event) {

func init() {
rootCmd.AddCommand(lsCmd)
lsCmd.PersistentFlags().BoolVar(&listArchived, "archive", false, "list archived events")
}
12 changes: 11 additions & 1 deletion cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/spf13/cobra"
)

var searchInArchived bool

// searchCmd represents the search command
var searchCmd = &cobra.Command{
Use: "search",
Expand All @@ -26,7 +28,14 @@ ere search "^deadline.*urgent"
fmt.Println("error in regular expression")
log.Fatal(err)
}
allEvents := eventsFromEventsFile(ereActiveEventsFileName)
var fileName string
if listArchived {
fileName = ereArchivedEventsFileName
} else {
fileName = ereActiveEventsFileName
}
allEvents := eventsFromEventsFile(fileName)

filteredEvents := make([]Event, 0)
for _, e := range allEvents {
if searchRegex.Match([]byte(e.Title)) {
Expand All @@ -40,4 +49,5 @@ ere search "^deadline.*urgent"

func init() {
rootCmd.AddCommand(searchCmd)
searchCmd.PersistentFlags().BoolVar(&listArchived, "archive", false, "search through archived events")
}

0 comments on commit e5997c1

Please sign in to comment.