Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#232 - default time entry options per folder #241

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dist: deps-install dist/darwin dist/linux dist/windows ## build all cli versions

dist-internal:
mkdir -p dist/$(goos)
GOOS=$(goos) GOARCH=$(goarch) go build -o dist/$(goos)/clockify-cli $(MAIN_PKG)
CGO_ENABLED=0 GOOS=$(goos) GOARCH=$(goarch) go build -o dist/$(goos)/clockify-cli $(MAIN_PKG)

dist/darwin:
make dist-internal goos=darwin goarch=amd64
Expand Down
14 changes: 10 additions & 4 deletions internal/consoletest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ExpectConsole interface {
ExpectEOF()
ExpectString(string)
Send(string)
SendLine(string)
SendLine(...string)
}

type console struct {
Expand All @@ -43,9 +43,15 @@ func (c *console) Send(s string) {
}
}

func (c *console) SendLine(s string) {
if _, err := c.c.SendLine(s); err != nil {
c.t.Errorf("failed to SendLine %v", err)
func (c *console) SendLine(s ...string) {
if len(s) == 0 {
s = []string{""}
}

for i := range s {
if _, err := c.c.SendLine(s[i]); err != nil {
c.t.Errorf("failed to SendLine %v", err)
}
}
}

Expand Down
5 changes: 5 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,7 @@ type Config interface {
type Client interface {
api.Client
}

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 @@ -114,6 +114,11 @@ func (d *SimpleConfig) IsInteractive() bool {
return d.Interactive
}

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

func (d *SimpleConfig) GetWorkWeekdays() []string {
return d.WorkweekDays
}
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 @@ -36,9 +36,13 @@ 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_LANGUAGE: "which language to use for number " +
"formatting",
cmdutil.CONF_TIMEZONE: "which timezone to use to input/output time",
cmdutil.CONF_TIME_ENTRY_DEFAULTS: "should load defaults for time " +
"entries from current folder",
}

// NewCmdConfig represents the config command
Expand Down
18 changes: 14 additions & 4 deletions pkg/cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ func NewCmdInit(f cmdutil.Factory) *cobra.Command {
"Should suggest and allow creating time entries "+
"with archived tags?",
),
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/",
),
),
setLanguage(i, config),
setTimezone(i, config),
); err != nil {
Expand Down Expand Up @@ -268,15 +280,13 @@ func updateInt(ui ui.UI, config cmdutil.Config, param, desc string,

func updateFlag(
ui ui.UI, config cmdutil.Config, param, description string,
) func() error {
opts ...ui.ConfirmOption) func() error {
return func() (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)
return
}

}
Loading
Loading