Skip to content

Commit

Permalink
you can ls plain lines, youre welcome fzf users
Browse files Browse the repository at this point in the history
  • Loading branch information
prmaloney committed Jan 23, 2024
1 parent af2dd13 commit 26ab8b6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ var projectCmd = &cobra.Command{
Short: "List projects",
Run: func(cmd *cobra.Command, args []string) {
projects, _ := data.GetProjects()
if lines, err := cmd.Flags().GetBool("lines"); err == nil && lines {
for _, project := range projects {
fmt.Printf("%d %s\n", project.Id, project.GetName())
}
return
}
t := table.New().
Border(lipgloss.RoundedBorder()).
Headers("ID", "Name").
Expand Down Expand Up @@ -53,7 +59,16 @@ var taskCmd = &cobra.Command{
return
}


projects, _ := data.GetProjects()
if lines, err := cmd.Flags().GetBool("lines"); err == nil && lines {
for _, project := range projects {
for _, task := range project.Tasks {
fmt.Printf("%d\t%s\n", task.Id, task.Name)
}
}
return
}
for _, project := range projects {
tasks := project.Tasks
for _, task := range tasks {
Expand Down Expand Up @@ -97,6 +112,18 @@ var activityCmd = &cobra.Command{
rows = append(rows, []string{id, date, time, desc})
}
}
if lines, err := cmd.Flags().GetBool("lines"); err == nil && lines {
for i := 0; i < len(rows); i++ {
for j := 0; j < len(rows[i]); j++ {
fmt.Print(rows[i][j])
if j < len(rows[i])-1 {
fmt.Print("\t")
}
}
fmt.Println()
}
return
}
t := table.New().
Border(lipgloss.RoundedBorder()).
Headers("ID", "Date", "Time", "Description").
Expand All @@ -122,13 +149,17 @@ var lsCmd = &cobra.Command{
}

func init() {
projectCmd.Flags().BoolP("lines", "l", false, "List in lines")
lsCmd.AddCommand(projectCmd)

taskCmd.Flags().IntP("project", "p", 0, "Project ID")
taskCmd.Flags().BoolP("lines", "l", false, "List in lines")
lsCmd.AddCommand(taskCmd)

activityCmd.Flags().BoolP("today", "t", false, "List tasks for today")
activityCmd.Flags().BoolP("lines", "l", false, "List in lines")
lsCmd.AddCommand(activityCmd)


rootCmd.AddCommand(lsCmd)
}

0 comments on commit 26ab8b6

Please sign in to comment.