From 26ab8b61d2bebe070856f61bc2ad0c2ea5de44b1 Mon Sep 17 00:00:00 2001 From: Patrick Maloney Date: Tue, 23 Jan 2024 16:48:05 +0100 Subject: [PATCH] you can ls plain lines, youre welcome fzf users --- cmd/ls.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmd/ls.go b/cmd/ls.go index 81fd95c..84ec1bf 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -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"). @@ -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 { @@ -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"). @@ -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) }