Skip to content

Commit

Permalink
feat: back to cobra
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 14, 2022
1 parent 6277b04 commit cdf337a
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ require (
github.com/charmbracelet/lipgloss v0.5.0
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/mattn/go-isatty v0.0.14
github.com/muesli/coral v1.0.0
github.com/muesli/go-app-paths v0.2.2
github.com/muesli/mango-coral v1.0.1
github.com/muesli/mango-cobra v1.1.0
github.com/muesli/roff v0.1.0
github.com/spf13/cobra v1.4.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,12 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/coral v1.0.0 h1:odyqkoEg4aJAINOzvnjN4tUsdp+Zleccs7tRIAkkYzU=
github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8=
github.com/muesli/go-app-paths v0.2.2 h1:NqG4EEZwNIhBq/pREgfBmgDmt3h1Smr1MjZiXbpZUnI=
github.com/muesli/go-app-paths v0.2.2/go.mod h1:SxS3Umca63pcFcLtbjVb+J0oD7cl4ixQWoBKhGEtEho=
github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-coral v1.0.1 h1:W3nGbUC/q5vLscQ6GPzteHZrJI1Msjw5Hns82o0xRkI=
github.com/muesli/mango-coral v1.0.1/go.mod h1:EPSlYH67AtcxQrxssNw6r/lMFxHTjuDoGfq9Uxxevhg=
github.com/muesli/mango-cobra v1.1.0 h1:j/mM5omhC2Vw8pim716aMJVElIRln089XZJ2JY7Xjzc=
github.com/muesli/mango-cobra v1.1.0/go.mod h1:lotV+49eKrAV0tTw/ONhLsiyKwM5uW5QP2OkYw4xlNc=
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
Expand Down Expand Up @@ -167,6 +165,8 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cmd

import "github.com/muesli/coral"
import "github.com/spf13/cobra"

type completionCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newCompletionCmd() *completionCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "completion [bash|zsh|fish]",
Short: "Print shell autocompletion scripts for tt",
Long: `To load completions:
Expand All @@ -34,8 +34,8 @@ Fish:
DisableFlagsInUseLine: true,
Hidden: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: coral.ExactValidArgs(1),
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
switch args[0] {
case "bash":
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"strings"
"time"

"github.com/muesli/coral"
"github.com/spf13/cobra"
)

type editCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newEditCmd() *editCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "edit",
Short: "Syntactic sugar for to-json | $EDITOR | from-json",
Aliases: []string{"e"},
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
tmp := filepath.Join(os.TempDir(), fmt.Sprintf("tt-%d.json", time.Now().Unix()))

if err := newToJSONCmd().cmd.RunE(cmd, []string{tmp}); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/fromjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (

"github.com/caarlos0/tasktimer/internal/model"
"github.com/caarlos0/tasktimer/internal/store"
"github.com/muesli/coral"
"github.com/spf13/cobra"
)

type fromJSONCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newFromJSONCmd() *fromJSONCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "from-json",
Short: "Imports a JSON into a project - WARNING: it will wipe the project first, use with care!",
Args: coral.ExactArgs(1),
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
project := cmd.Parent().Flag("project").Value.String()
db, f, err := setup(project)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (

"github.com/charmbracelet/glamour"
"github.com/mattn/go-isatty"
"github.com/muesli/coral"
gap "github.com/muesli/go-app-paths"
"github.com/spf13/cobra"
)

type listCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newListCmd() *listCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "list",
Short: "List all projects",
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
home := gap.NewScope(gap.User, "tasktimer")
datas, err := home.DataDirs()
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions internal/cmd/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import (
"fmt"
"os"

"github.com/muesli/coral"
mcoral "github.com/muesli/mango-coral"
mcobra "github.com/muesli/mango-cobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
)

type manCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newManCmd() *manCmd {
root := &manCmd{}
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "man",
Short: "Generates tt's command line manpages",
SilenceUsage: true,
DisableFlagsInUseLine: true,
Hidden: true,
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
manPage, err := mcoral.NewManPage(1, root.cmd.Root())
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
manPage, err := mcobra.NewManPage(1, root.cmd.Root())
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package cmd
import (
"fmt"

"github.com/muesli/coral"
"github.com/spf13/cobra"
)

type pathsCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newPathsCmd() *pathsCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "paths",
Short: "Print the paths being used for logs, data et al",
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
project := cmd.Parent().Flag("project").Value.String()
logfile, dbfile, err := paths(project)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"github.com/caarlos0/tasktimer/internal/ui"
"github.com/charmbracelet/glamour"
"github.com/mattn/go-isatty"
"github.com/muesli/coral"
"github.com/spf13/cobra"
)

type reportCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newRerportCmd() *reportCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "report",
Aliases: []string{"r"},
Short: "Print a markdown report of the given project to STDOUT",
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
project := cmd.Parent().Flag("project").Value.String()
db, f, err := setup(project)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package cmd
import (
"github.com/caarlos0/tasktimer/internal/ui"
tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/coral"
"github.com/spf13/cobra"
)

func Execute(version string, exit func(int), args []string) {
newRootCmd(version, exit).Execute(args)
}

type rootCmd struct {
cmd *coral.Command
cmd *cobra.Command
project string
exit func(int)
}
Expand All @@ -27,12 +27,12 @@ func newRootCmd(version string, exit func(int)) *rootCmd {
root := &rootCmd{
exit: exit,
}
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "tt",
Short: "Task Timer (tt) is a dead simple TUI task timer",
Version: version,
SilenceUsage: true,
RunE: func(cmd *coral.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
db, f, err := setup(root.project)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/tojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"os"

"github.com/caarlos0/tasktimer/internal/ui"
"github.com/muesli/coral"
"github.com/spf13/cobra"
)

type toJSONCmd struct {
cmd *coral.Command
cmd *cobra.Command
}

func newToJSONCmd() *toJSONCmd {
cmd := &coral.Command{
cmd := &cobra.Command{
Use: "to-json",
Short: "Exports the database as JSON",
Args: coral.MaximumNArgs(1),
RunE: func(cmd *coral.Command, args []string) error {
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
project := cmd.Parent().Flag("project").Value.String()
db, f, err := setup(project)
if err != nil {
Expand Down

0 comments on commit cdf337a

Please sign in to comment.