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

issue: 169 - shell auto complete using client and project names #270

Merged
merged 2 commits into from
Jun 13, 2024
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- new config `lang` to allow setting the number format to be used when printing
- support to using client's name or id for autocompletion on bash

## [v0.52.0] - 2024-06-02

Expand Down
3 changes: 1 addition & 2 deletions cmd/gendocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func execute() error {
return "/en/commands/" + strings.ToLower(base) + "/"
}

var f cmdutil.Factory
cmd := cmd.NewCmdRoot(f)
cmd := cmd.NewCmdRoot(cmdutil.NewFactory(cmdutil.Version{}))

fmt.Println("Generating Hugo command-line documentation in", docdir, "...")
err := doc.GenMarkdownTreeCustom(cmd, docdir, prepender, linkHandler)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/project/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewCmdGet(
Use: "get",
Args: cmdutil.RequiredNamedArgs("project"),
ValidArgsFunction: cmdcompl.CombineSuggestionsToArgs(
cmdcomplutil.NewProjectAutoComplete(f)),
cmdcomplutil.NewProjectAutoComplete(f, f.Config())),
Short: "Get a project on a Clockify workspace",
Example: heredoc.Docf(`
$ %[1]s 621948458cb9606d934ebb1c
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/project/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func TestCmdGet(t *testing.T) {
args: []string{"--format={}", "-q", "-j", "p1"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

return f
},
},
{
Expand All @@ -46,6 +49,8 @@ func TestCmdGet(t *testing.T) {
args: []string{"p1"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

f.EXPECT().GetWorkspaceID().
Return("", errors.New("workspace error"))
return f
Expand All @@ -57,6 +62,8 @@ func TestCmdGet(t *testing.T) {
args: []string{"p1"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})

f.EXPECT().GetWorkspaceID().
Return("w", nil)
f.EXPECT().Client().Return(nil, errors.New("client error"))
Expand Down
57 changes: 27 additions & 30 deletions pkg/cmd/task/add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func TestCmdAdd(t *testing.T) {
}
}

dFactory := func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
}

tts := []struct {
name string
args []string
Expand All @@ -37,44 +43,34 @@ func TestCmdAdd(t *testing.T) {
err string
}{
{
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-n=OK", "-p=OK"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-n=OK", "-p=OK"},
err: "flags can't be used together.*format.*json.*quiet",
factory: dFactory,
},
{
name: "billable or not",
args: []string{"--billable", "--not-billable", "-n=OK", "-p=OK"},
err: "flags can't be used together.*billable.*not-billable",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "billable or not",
args: []string{"--billable", "--not-billable", "-n=OK", "-p=OK"},
err: "flags can't be used together.*billable.*not-billable",
factory: dFactory,
},
{
name: "assignee or no assignee",
args: []string{"--assignee=l", "--no-assignee", "-n=OK", "-p=OK"},
err: "flags can't be used together.*assignee.*no-assignee",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "assignee or no assignee",
args: []string{"--assignee=l", "--no-assignee", "-n=OK", "-p=OK"},
err: "flags can't be used together.*assignee.*no-assignee",
factory: dFactory,
},
{
name: "name required",
args: []string{"-p=OK"},
err: `"name" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "name required",
args: []string{"-p=OK"},
err: `"name" not set`,
factory: dFactory,
},
{
name: "project required",
args: []string{"-n=OK"},
err: `"project" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project required",
args: []string{"-n=OK"},
err: `"project" not set`,
factory: dFactory,
},
{
name: "client error",
Expand All @@ -97,6 +93,7 @@ func TestCmdAdd(t *testing.T) {
args: []string{"-n=a", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("", errors.New("workspace error"))
return f
Expand Down
10 changes: 8 additions & 2 deletions pkg/cmd/task/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ func TestCmdDelete(t *testing.T) {
args: []string{},
err: "requires arg task",
params: func(t *testing.T) (cmdutil.Factory, report) {
return mocks.NewMockFactory(t), nil
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f, nil
},
},
{
name: "project is required",
err: "flag.*project.*not set",
args: []string{"task-id"},
params: func(t *testing.T) (cmdutil.Factory, report) {
return mocks.NewMockFactory(t), nil
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f, nil
},
},
{
Expand All @@ -48,6 +52,7 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").Return("", errors.New("w error"))
return f, nil
},
Expand All @@ -58,6 +63,7 @@ func TestCmdDelete(t *testing.T) {
args: []string{"task-id", "-p", "p-1"},
params: func(t *testing.T) (cmdutil.Factory, report) {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").Return("w", nil)
f.On("Client").Return(nil, errors.New("c error"))
return f, nil
Expand Down
68 changes: 32 additions & 36 deletions pkg/cmd/task/done/done_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestCmdDone(t *testing.T) {
}
}

dFactory := func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
}

tts := []struct {
name string
args []string
Expand All @@ -38,59 +44,48 @@ func TestCmdDone(t *testing.T) {
err string
}{
{
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: dFactory,
},
{
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: dFactory,
},
{
name: "project not empty",
args: []string{"task", "-p= "},
err: `project should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project not empty",
args: []string{"task", "-p= "},
err: `project should not be empty`,
factory: dFactory,
},
{
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id/name should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id/name should not be empty`,
factory: dFactory,
},
{
name: "task id not empty (nice try)",
args: []string{"not-empty", " ", "-p=cli"},
err: `task id/name should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id not empty (nice try)",
args: []string{"not-empty", " ", "-p=cli"},
err: `task id/name should not be empty`,
factory: dFactory,
},
{
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "done"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "done"},
err: "flags can't be used together.*format.*json.*quiet",
factory: dFactory,
},
{
name: "client error",
err: "client error",
args: []string{"done", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("w", nil)

Expand All @@ -104,6 +99,7 @@ func TestCmdDone(t *testing.T) {
args: []string{"done", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("", errors.New("workspace error"))
return f
Expand Down
66 changes: 30 additions & 36 deletions pkg/cmd/task/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TestCmdEdit(t *testing.T) {
return nil
}
}
dFactory := func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
return f
}

tts := []struct {
name string
Expand All @@ -38,52 +43,40 @@ func TestCmdEdit(t *testing.T) {
err string
}{
{
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id required",
args: []string{"-p=cli"},
err: `requires arg task`,
factory: dFactory,
},
{
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "project required",
args: []string{"task"},
err: `"project" not set`,
factory: dFactory,
},
{
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id should not be empty`,
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "task id not empty",
args: []string{" ", "-p=cli"},
err: `task id should not be empty`,
factory: dFactory,
},
{
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "edit"},
err: "flags can't be used together.*format.*json.*quiet",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "only one format",
args: []string{"--format={}", "-q", "-j", "-p=OK", "edit"},
err: "flags can't be used together.*format.*json.*quiet",
factory: dFactory,
},
{
name: "billable or not",
args: []string{"--billable", "--not-billable", "edit", "-p=OK"},
err: "flags can't be used together.*billable.*not-billable",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "billable or not",
args: []string{"--billable", "--not-billable", "edit", "-p=OK"},
err: "flags can't be used together.*billable.*not-billable",
factory: dFactory,
},
{
name: "assignee or no assignee",
args: []string{"--assignee=l", "--no-assignee", "edit", "-p=OK"},
err: "flags can't be used together.*assignee.*no-assignee",
factory: func(t *testing.T) cmdutil.Factory {
return mocks.NewMockFactory(t)
},
name: "assignee or no assignee",
args: []string{"--assignee=l", "--no-assignee", "edit", "-p=OK"},
err: "flags can't be used together.*assignee.*no-assignee",
factory: dFactory,
},
{
name: "client error",
Expand All @@ -106,6 +99,7 @@ func TestCmdEdit(t *testing.T) {
args: []string{"edit", "-p=b"},
factory: func(t *testing.T) cmdutil.Factory {
f := mocks.NewMockFactory(t)
f.EXPECT().Config().Return(&mocks.SimpleConfig{})
f.On("GetWorkspaceID").
Return("", errors.New("workspace error"))
return f
Expand Down
Loading
Loading