diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-12-05 17:46:53 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-12-05 17:46:53 +0300 |
commit | bcdbe68ecde049ef62343584bcc26840322c4864 (patch) | |
tree | 4a02b4da5db29ab3f3526ff475db859293a97646 /cmd/add.go |
Initial commit
Diffstat (limited to 'cmd/add.go')
-rw-r--r-- | cmd/add.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cmd/add.go b/cmd/add.go new file mode 100644 index 0000000..b8979b0 --- /dev/null +++ b/cmd/add.go @@ -0,0 +1,48 @@ +package cmd + +import ( + "strings" + + "github.com/spf13/cobra" +) + +// addCmd represents the add command +var addCmd = &cobra.Command{ + Use: "add", + Short: "Add activity", + Long: `Add new activity that we can track`, + Run: func(cmd *cobra.Command, args []string) { + titles := []string{} + tags := []string{} + contexts := []string{} + for _, s := range args { + if len(s) == 0 { + continue + } + if s[0:1] == "#" { + if len(s[1:]) >= 1 { + tags = append(tags, s[1:]) + continue + } + } + if s[0:1] == "@" { + if len(s[1:]) >= 1 { + contexts = append(contexts, s[1:]) + continue + } + } + titles = append(titles, s) + } + title := strings.Join(titles, " ") + activityID, err := tr.Add(title, tags, contexts) + if err != nil { + cmd.PrintErr(err) + return + } + cmd.Printf("Activity #%d added! Now you can start it.\n", activityID) + }, +} + +func init() { + rootCmd.AddCommand(addCmd) +} |