Skip to content

Commit

Permalink
Merge pull request #8 from foobaragency/1-l-flag-for-ls-for-plain-lines
Browse files Browse the repository at this point in the history
you can ls plain lines, youre welcome fzf users
  • Loading branch information
prmaloney authored Jan 23, 2024
2 parents af2dd13 + 26ab8b6 commit a92397f
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 a92397f

Please sign in to comment.