aboutsummaryrefslogtreecommitdiff
path: root/cmd/ls.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-12-05 17:46:53 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-12-05 17:46:53 +0300
commitbcdbe68ecde049ef62343584bcc26840322c4864 (patch)
tree4a02b4da5db29ab3f3526ff475db859293a97646 /cmd/ls.go
Initial commit
Diffstat (limited to 'cmd/ls.go')
-rw-r--r--cmd/ls.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/ls.go b/cmd/ls.go
new file mode 100644
index 0000000..3fe7244
--- /dev/null
+++ b/cmd/ls.go
@@ -0,0 +1,66 @@
+package cmd
+
+import (
+ "strings"
+
+ "github.com/spf13/cobra"
+)
+
+// lsCmd represents the ls command
+var lsCmd = &cobra.Command{
+ Use: "ls",
+ Short: "List activities",
+ Long: `List started (or all by -a flag) activities`,
+ Run: func(cmd *cobra.Command, args []string) {
+ all, err := cmd.Flags().GetBool("all")
+ if err != nil {
+ cmd.PrintErr(err)
+ return
+ }
+ verbose, err := cmd.Flags().GetBool("verbose")
+ if err != nil {
+ cmd.PrintErr(err)
+ return
+ }
+ activities := tr.List(all)
+ if len(activities) == 0 {
+ cmd.Printf("There is no activities.\n")
+ return
+ }
+ if all {
+ cmd.Printf("Activities:\n")
+ } else {
+ cmd.Printf("Started activities:\n")
+ }
+ for _, activity := range activities {
+ cmd.Printf("%d. %s\n", activity.ID, activity.Title)
+ if len(activity.Tags) > 0 {
+ cmd.Printf("\tTags: %v\n", activity.Tags)
+ }
+ if len(activity.Context) > 0 {
+ cmd.Printf("\tContexts: %v\n", activity.Context)
+ }
+ cmd.Printf("\t%d timespans\n", len(activity.Spans))
+ for i, span := range activity.Spans {
+ if !verbose && i < len(activity.Spans)-1 {
+ continue
+ }
+ stop := "now"
+ if span.Stop != nil {
+ stop = span.Stop.Format("15:04:05 2.1.2006")
+ }
+ if strings.Trim(span.Comment, " ") != "" {
+ cmd.Printf("\t%s — %s: \"%s\"\n", span.Start.Format("15:04:05 2.1.2006"), stop, span.Comment)
+ } else {
+ cmd.Printf("\t%s — %s\n", span.Start.Format("15:04:05 2.1.2006"), stop)
+ }
+ }
+ }
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(lsCmd)
+ lsCmd.Flags().BoolP("all", "a", false, "List all activities. Only started by default")
+ lsCmd.Flags().BoolP("verbose", "v", false, "List all timespans. Only last by default")
+}