Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Apr 6, 2024
1 parent 042b41d commit 1c65b48
Show file tree
Hide file tree
Showing 43 changed files with 2,301 additions and 215 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ packages:
Client:
Config:
Factory:
TimeEntryDefaults:
6 changes: 6 additions & 0 deletions internal/mocks/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mocks

import (
"github.com/lucassabreu/clockify-cli/api"
"github.com/lucassabreu/clockify-cli/pkg/cmd/time-entry/util/defaults"
"github.com/lucassabreu/clockify-cli/pkg/cmdutil"
)

Expand All @@ -16,3 +17,8 @@ type Config interface {
type Client interface {
api.Client
}

//go:generate mockery --name=TimeEntryDefaults --inpackage --with-expecter
type TimeEntryDefaults interface {
defaults.TimeEntryDefaults
}
45 changes: 45 additions & 0 deletions internal/mocks/mock_Config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions internal/mocks/mock_Factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions internal/mocks/mock_TimeEntryDefaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/mocks/simple_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func (s *SimpleConfig) IsSearchProjectWithClientsName() bool {
return s.SearchProjectWithClientsName
}

// IsAllowArchivedTags defines if archived tags should be suggested
func (s *SimpleConfig) IsAllowArchivedTags() bool {
return s.AllowArchivedTags
}

// InteractivePageSize sets how many items are shown when prompting
// projects
func (s *SimpleConfig) InteractivePageSize() int {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ var validParameters = cmdcompl.ValidArgsMap{
cmdutil.CONF_LOG_LEVEL: "how much logs should be shown values: " +
"none , error , info and debug",
cmdutil.CONF_ALLOW_ARCHIVED_TAGS: "should allow and suggest archived tags",
cmdutil.CONF_INTERACTIVE_PAGE_SIZE: "how many entries should be listed " +
"when prompting options",
cmdutil.CONF_TIME_ENTRY_DEFAULTS: "should load defaults for time " +
"entries from current folder",
}

// NewCmdConfig represents the config command
Expand Down
22 changes: 20 additions & 2 deletions pkg/cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ func NewCmdInit(f cmdutil.Factory) *cobra.Command {
return err
}

if err := updateFlag(i, config, cmdutil.CONF_TIME_ENTRY_DEFAULTS,
"Look for default parameters for time entries per folder?",
ui.WithConfirmHelp(
"This will set the default parameters of a time entry "+
"when using `clockify-cli in` and `clockify-cli "+
"manual` to the closest .clockify-defaults.yaml file "+
"looking up the current folder you were running the"+
" commands.\n"+
"For more information and examples go to "+
"https://clockify-cli.netlify.app/",
),
); err != nil {
return err

Check warning on line 188 in pkg/cmd/config/init/init.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/config/init/init.go#L188

Added line #L188 was not covered by tests
}

config.SetString(cmdutil.CONF_TOKEN, token)

return config.Save()
},
}
Expand All @@ -191,9 +208,10 @@ func updateInt(ui ui.UI, config cmdutil.Config, param, desc string) error {
}

func updateFlag(
ui ui.UI, config cmdutil.Config, param, description string) (err error) {
ui ui.UI, config cmdutil.Config, param, description string,
opts ...ui.ConfirmOption) (err error) {
b := config.GetBool(param)
if b, err = ui.Confirm(description, b); err != nil {
if b, err = ui.Confirm(description, b, opts...); err != nil {
return
}
config.SetBool(param, b)
Expand Down
16 changes: 15 additions & 1 deletion pkg/cmd/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import (
)

func setStringFn(config *mocks.MockConfig, name, value string) *mock.Call {
r := ""
return setStringDefaultFn(config, name, "", value)
}

func setStringDefaultFn(
config *mocks.MockConfig, name, first, value string) *mock.Call {
r := first
config.On("GetString", name).
Return(func(string) string {
v := r
Expand Down Expand Up @@ -106,6 +111,8 @@ func TestInitCmd(t *testing.T) {

setBoolFn(config, cmdutil.CONF_ALLOW_ARCHIVED_TAGS, true, false)

setBoolFn(config, cmdutil.CONF_TIME_ENTRY_DEFAULTS, false, true)

config.EXPECT().Save().Once().Return(nil)

f.EXPECT().UI().Return(ui.NewUI(in, out, out))
Expand Down Expand Up @@ -195,6 +202,13 @@ func TestInitCmd(t *testing.T) {
c.SendLine("n")
c.ExpectString("No")

c.ExpectString(
"Look for default parameters for time entries per folder?")
c.SendLine("?")
c.ExpectString("https://")
c.SendLine("y")
c.ExpectString("Yes")

c.ExpectEOF()
})
}
Expand Down
Loading

0 comments on commit 1c65b48

Please sign in to comment.