flick
This commit is contained in:
parent
8f08151c00
commit
ad9f720b35
4 changed files with 33 additions and 14 deletions
11
cmd/add.go
11
cmd/add.go
|
@ -3,7 +3,10 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/neonxp/track/internal/tracker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// addCmd represents the add command
|
// addCmd represents the add command
|
||||||
|
@ -34,6 +37,14 @@ var addCmd = &cobra.Command{
|
||||||
titles = append(titles, s)
|
titles = append(titles, s)
|
||||||
}
|
}
|
||||||
title := strings.Join(titles, " ")
|
title := strings.Join(titles, " ")
|
||||||
|
|
||||||
|
fs := afero.NewOsFs()
|
||||||
|
tr, err := tracker.New(fs)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
activityID, err := tr.Add(title, tags, contexts)
|
activityID, err := tr.Add(title, tags, contexts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErr(err)
|
cmd.PrintErr(err)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/neonxp/track/internal/tracker"
|
"github.com/neonxp/track/internal/tracker"
|
||||||
|
@ -25,7 +26,15 @@ var lsCmd = &cobra.Command{
|
||||||
cmd.PrintErr(err)
|
cmd.PrintErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs := afero.NewOsFs()
|
||||||
|
tr, err := tracker.New(fs)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
activities := tr.List(all)
|
activities := tr.List(all)
|
||||||
|
|
||||||
if len(activities) == 0 {
|
if len(activities) == 0 {
|
||||||
cmd.Printf("There is no activities.\n")
|
cmd.Printf("There is no activities.\n")
|
||||||
return
|
return
|
||||||
|
|
13
cmd/root.go
13
cmd/root.go
|
@ -4,12 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/neonxp/track/internal/tracker"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cfgFile string
|
var cfgFile string
|
||||||
|
@ -21,18 +18,9 @@ var rootCmd = &cobra.Command{
|
||||||
Long: `Track time spent for any work or personal activities`,
|
Long: `Track time spent for any work or personal activities`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var tr *tracker.Tracker
|
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
fs := afero.NewOsFs()
|
|
||||||
var err error
|
|
||||||
tr, err = tracker.New(fs)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,4 +53,3 @@ func initConfig() {
|
||||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
cmd/start.go
12
cmd/start.go
|
@ -4,7 +4,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/neonxp/track/internal/tracker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// startCmd represents the start command
|
// startCmd represents the start command
|
||||||
|
@ -23,11 +26,20 @@ var startCmd = &cobra.Command{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
comment := strings.Join(args[1:], " ")
|
comment := strings.Join(args[1:], " ")
|
||||||
|
|
||||||
|
fs := afero.NewOsFs()
|
||||||
|
tr, err := tracker.New(fs)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := tr.Start(id, comment); err != nil {
|
if err := tr.Start(id, comment); err != nil {
|
||||||
cmd.PrintErr(err)
|
cmd.PrintErr(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
activity := tr.Activity(id)
|
activity := tr.Activity(id)
|
||||||
|
|
||||||
cmd.Printf("Started new span for activity \"%s\".\n", activity.Title)
|
cmd.Printf("Started new span for activity \"%s\".\n", activity.Title)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue