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 (
|
||||
"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)
|
||||
|
|
|
@ -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
|
||||
|
|
13
cmd/root.go
13
cmd/root.go
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
cmd/start.go
12
cmd/start.go
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue