-
Notifications
You must be signed in to change notification settings - Fork 23
/
root.go
83 lines (64 loc) · 2.73 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cmd
import (
"github.com/lucassabreu/clockify-cli/pkg/cmd/client"
"github.com/lucassabreu/clockify-cli/pkg/cmd/completion"
"github.com/lucassabreu/clockify-cli/pkg/cmd/config"
"github.com/lucassabreu/clockify-cli/pkg/cmd/project"
"github.com/lucassabreu/clockify-cli/pkg/cmd/tag"
"github.com/lucassabreu/clockify-cli/pkg/cmd/task"
timeentry "github.com/lucassabreu/clockify-cli/pkg/cmd/time-entry"
"github.com/lucassabreu/clockify-cli/pkg/cmd/user"
"github.com/lucassabreu/clockify-cli/pkg/cmd/user/me"
"github.com/lucassabreu/clockify-cli/pkg/cmd/version"
"github.com/lucassabreu/clockify-cli/pkg/cmd/workspace"
"github.com/lucassabreu/clockify-cli/pkg/cmdcompl"
"github.com/lucassabreu/clockify-cli/pkg/cmdcomplutil"
"github.com/lucassabreu/clockify-cli/pkg/cmdutil"
"github.com/spf13/cobra"
)
// NewCmdRoot creates the base command when called without any subcommands
func NewCmdRoot(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "clockify-cli",
Short: "Allow to integrate with Clockify through terminal",
SilenceErrors: true,
SilenceUsage: true,
}
cmd.PersistentFlags().StringP("token", "t", "",
"clockify's token\nCan be generated here: "+
"https://clockify.me/user/settings#generateApiKeyBtn")
cmd.PersistentFlags().StringP("workspace", "w", "", "workspace to be used")
_ = cmdcompl.AddSuggestionsToFlag(cmd, "workspace",
cmdcomplutil.NewWorspaceAutoComplete(f))
cmd.PersistentFlags().StringP("user-id", "u", "", "user id from the token")
_ = cmdcompl.AddSuggestionsToFlag(cmd, "user-id",
cmdcomplutil.NewUserAutoComplete(f))
cmd.PersistentFlags().BoolP("interactive", "i", false,
"will prompt you to confirm/complement commands input before "+
"executing the action ")
cmd.PersistentFlags().IntP("interactive-page-size", "L", 7,
"will set how many items will be shown on interactive mode")
cmd.PersistentFlags().BoolP("allow-name-for-id", "", false,
"allow use of project/client/tag's name when id is asked")
cmd.PersistentFlags().String(
"log-level", cmdutil.LOG_LEVEL_NONE, "set log level")
_ = cmdcompl.AddFixedSuggestionsToFlag(cmd, "log-level",
cmdcompl.ValidArgsSlide{
cmdutil.LOG_LEVEL_NONE,
cmdutil.LOG_LEVEL_DEBUG,
cmdutil.LOG_LEVEL_INFO,
})
_ = cmd.MarkFlagRequired("token")
cmd.AddCommand(version.NewCmdVersion(f))
cmd.AddCommand(config.NewCmdConfig(f))
cmd.AddCommand(workspace.NewCmdWorkspace(f))
cmd.AddCommand(user.NewCmdUser(f, nil))
cmd.AddCommand(me.NewCmdMe(f, nil))
cmd.AddCommand(client.NewCmdClient(f))
cmd.AddCommand(project.NewCmdProject(f))
cmd.AddCommand(task.NewCmdTask(f))
cmd.AddCommand(tag.NewCmdTag(f))
cmd.AddCommand(timeentry.NewCmdTimeEntry(f)...)
cmd.AddCommand(completion.NewCmdCompletion())
return cmd
}