This commit is contained in:
Alexander Kiryukhin 2021-12-18 02:29:55 +03:00
parent 8f08151c00
commit ad9f720b35
No known key found for this signature in database
GPG key ID: 6DF7A2910D0699E9
4 changed files with 33 additions and 14 deletions

View file

@ -3,7 +3,10 @@ package cmd
import (
"strings"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/neonxp/track/internal/tracker"
)
// addCmd represents the add command
@ -34,6 +37,14 @@ var addCmd = &cobra.Command{
titles = append(titles, s)
}
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)
if err != nil {
cmd.PrintErr(err)

View file

@ -4,6 +4,7 @@ import (
"strings"
"time"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/neonxp/track/internal/tracker"
@ -25,7 +26,15 @@ var lsCmd = &cobra.Command{
cmd.PrintErr(err)
return
}
fs := afero.NewOsFs()
tr, err := tracker.New(fs)
if err != nil {
cmd.PrintErr(err)
return
}
activities := tr.List(all)
if len(activities) == 0 {
cmd.Printf("There is no activities.\n")
return

View file

@ -4,12 +4,9 @@ import (
"fmt"
"os"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/neonxp/track/internal/tracker"
)
var cfgFile string
@ -21,18 +18,9 @@ var rootCmd = &cobra.Command{
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.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
fs := afero.NewOsFs()
var err error
tr, err = tracker.New(fs)
if err != nil {
panic(err)
return
}
cobra.CheckErr(rootCmd.Execute())
}
@ -65,4 +53,3 @@ func initConfig() {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}

View file

@ -4,7 +4,10 @@ import (
"strconv"
"strings"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/neonxp/track/internal/tracker"
)
// startCmd represents the start command
@ -23,11 +26,20 @@ var startCmd = &cobra.Command{
return
}
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 {
cmd.PrintErr(err)
return
}
activity := tr.Activity(id)
cmd.Printf("Started new span for activity \"%s\".\n", activity.Title)
},
}