From 3af26faaf8470a78526ee545e2809489dbe99670 Mon Sep 17 00:00:00 2001 From: Tim Walsh Date: Fri, 28 Aug 2026 19:30:35 -0700 Subject: [PATCH 1/3] feat(task): add task archive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Archiving removes a task from active views while keeping its history and URL, which is the right primitive for retiring a task whose work has moved elsewhere. Closing it would assert a status the task never reached — and "closed" is not a status name on every list — while deleting destroys the record. The SDK cannot express this: clickup.TaskUpdateRequest has no archived field, so the request is built directly against the exported NewRequest/Do. Reversible with --undo; round-trip verified against a real workspace, with the task URL and status intact afterwards. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_014aqbmccWm1tqttmBUCR5rv ClickUp: 86dxbeqyt --- README.md | 4 +++ docs/site/commands/cu_task.md | 1 + docs/site/commands/cu_task_archive.md | 37 +++++++++++++++++++++++ internal/api/archive.go | 41 +++++++++++++++++++++++++ internal/cmd/task.go | 43 +++++++++++++++++++++++++++ mkdocs.yml | 1 + 6 files changed, 127 insertions(+) create mode 100644 docs/site/commands/cu_task_archive.md create mode 100644 internal/api/archive.go diff --git a/README.md b/README.md index f4d55f2..d0bcfbb 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ cu task create # View task details cu task view +# Archive a task (reversible; keeps history and URL) +cu task archive +cu task archive --undo + # Export tasks to CSV cu export tasks --format csv > tasks.csv ``` diff --git a/docs/site/commands/cu_task.md b/docs/site/commands/cu_task.md index a0a655b..4e4b42d 100644 --- a/docs/site/commands/cu_task.md +++ b/docs/site/commands/cu_task.md @@ -23,6 +23,7 @@ Create, view, update, and manage ClickUp tasks. ### SEE ALSO * [cu](cu.md) - A GitHub CLI-inspired command-line interface for ClickUp +* [cu task archive](cu_task_archive.md) - Archive a task * [cu task close](cu_task_close.md) - Close a task * [cu task create](cu_task_create.md) - Create a new task * [cu task interactive](cu_task_interactive.md) - Interactive task browser diff --git a/docs/site/commands/cu_task_archive.md b/docs/site/commands/cu_task_archive.md new file mode 100644 index 0000000..e572cca --- /dev/null +++ b/docs/site/commands/cu_task_archive.md @@ -0,0 +1,37 @@ +## cu task archive + +Archive a task + +### Synopsis + +Archive a task, removing it from active views while keeping its history +and URL intact. + +Archiving is reversible with --undo. Prefer it over closing a task whose work +has moved elsewhere: closing asserts a status the task never reached, and not +every list even has a status named "closed". + +``` +cu task archive [task-id] [flags] +``` + +### Options + +``` + -h, --help help for archive + --undo Unarchive instead of archiving +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.config/cu/config.yaml) + --debug enable debug mode + -o, --output string output format (table|json|yaml|csv) (default "table") +``` + +### SEE ALSO + +* [cu task](cu_task.md) - Manage tasks + +###### Auto generated by spf13/cobra on 28-Aug-2026 diff --git a/internal/api/archive.go b/internal/api/archive.go new file mode 100644 index 0000000..6e99198 --- /dev/null +++ b/internal/api/archive.go @@ -0,0 +1,41 @@ +package api + +import ( + "context" + "fmt" + + "github.com/raksul/go-clickup/clickup" +) + +// archiveRequest is sent directly rather than through clickup.TaskUpdateRequest, +// which has no archived field — the SDK cannot express this update. +type archiveRequest struct { + Archived bool `json:"archived"` +} + +// SetTaskArchived archives or unarchives a task. +// +// Archiving keeps the task, its history and its URL while removing it from +// active views. That makes it the right primitive for retiring a task whose +// work has moved elsewhere: closing it would assert a status the task never +// reached (and "closed" is not even a status name on every list), and deleting +// it destroys the record. +func (c *Client) SetTaskArchived(ctx context.Context, taskID string, archived bool) (*clickup.Task, error) { + if taskID == "" { + return nil, fmt.Errorf("a task id is required") + } + if err := c.rateLimiter.Wait(ctx); err != nil { + return nil, err + } + + req, err := c.client.NewRequest("PUT", fmt.Sprintf("task/%s", taskID), &archiveRequest{Archived: archived}) + if err != nil { + return nil, err + } + + task := new(clickup.Task) + if _, err := c.client.Do(ctx, req, task); err != nil { + return nil, c.handleError(err) + } + return task, nil +} diff --git a/internal/cmd/task.go b/internal/cmd/task.go index 4a0ea6f..c41feed 100644 --- a/internal/cmd/task.go +++ b/internal/cmd/task.go @@ -497,6 +497,47 @@ var taskReopenCmd = &cobra.Command{ }, } +var taskArchiveCmd = &cobra.Command{ + Use: "archive [task-id]", + Short: "Archive a task", + Long: `Archive a task, removing it from active views while keeping its history +and URL intact. + +Archiving is reversible with --undo. Prefer it over closing a task whose work +has moved elsewhere: closing asserts a status the task never reached, and not +every list even has a status named "closed".`, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + taskID := args[0] + undo, _ := cmd.Flags().GetBool("undo") + + client, err := api.NewClient() + if err != nil { + return err + } + + task, err := client.SetTaskArchived(context.Background(), taskID, !undo) + if err != nil { + return err + } + + verb := "Archived" + if undo { + verb = "Unarchived" + } + + if outputFormat != "table" { + return output.Format(outputFormat, task) + } + + fmt.Printf("✓ %s task %s: %s\n", verb, task.ID, task.Name) + if task.URL != "" { + fmt.Printf(" View in ClickUp: %s\n", task.URL) + } + return nil + }, +} + var taskSearchCmd = &cobra.Command{ Use: "search [query]", Short: "Search for tasks", @@ -683,6 +724,7 @@ func init() { taskCmd.AddCommand(taskCloseCmd) taskCmd.AddCommand(taskReopenCmd) taskCmd.AddCommand(taskSearchCmd) + taskCmd.AddCommand(taskArchiveCmd) // List command flags taskListCmd.Flags().StringP("list", "l", "", "List ID or name") @@ -719,6 +761,7 @@ func init() { taskUpdateCmd.Flags().StringSlice("remove-assignee", []string{}, "Remove assignees (username or ID)") // Reopen command flags + taskArchiveCmd.Flags().Bool("undo", false, "Unarchive instead of archiving") taskCloseCmd.Flags().StringP("status", "s", "", "Status to set (default: the list's done status)") taskReopenCmd.Flags().StringP("status", "s", "", "Status to set (default: the list's first open status)") diff --git a/mkdocs.yml b/mkdocs.yml index 43b4b31..c486d28 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -50,6 +50,7 @@ nav: - cu task close: commands/cu_task_close.md - cu task reopen: commands/cu_task_reopen.md - cu task search: commands/cu_task_search.md + - cu task archive: commands/cu_task_archive.md - cu task interactive: commands/cu_task_interactive.md - Lists: - cu list: commands/cu_list.md From b6bdf38aa30010adf7666778c7520f58a4219e98 Mon Sep 17 00:00:00 2001 From: Tim Walsh Date: Sun, 15 Nov 2026 11:23:40 -0700 Subject: [PATCH 2/3] fix(task): escape archive task id and match close/reopen error UX Escape the task ID with url.PathEscape when building the archive path. Set SilenceUsage on task archive so API failures no longer print the usage block, and wrap errors as "failed to archive/unarchive task". Give the --undo flag its own comment block. Co-Authored-By: Claude Opus 5.5 --- internal/api/archive.go | 3 ++- internal/cmd/task.go | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/api/archive.go b/internal/api/archive.go index 6e99198..b634e4c 100644 --- a/internal/api/archive.go +++ b/internal/api/archive.go @@ -3,6 +3,7 @@ package api import ( "context" "fmt" + "net/url" "github.com/raksul/go-clickup/clickup" ) @@ -28,7 +29,7 @@ func (c *Client) SetTaskArchived(ctx context.Context, taskID string, archived bo return nil, err } - req, err := c.client.NewRequest("PUT", fmt.Sprintf("task/%s", taskID), &archiveRequest{Archived: archived}) + req, err := c.client.NewRequest("PUT", "task/"+url.PathEscape(taskID), &archiveRequest{Archived: archived}) if err != nil { return nil, err } diff --git a/internal/cmd/task.go b/internal/cmd/task.go index c41feed..f802ae8 100644 --- a/internal/cmd/task.go +++ b/internal/cmd/task.go @@ -507,23 +507,25 @@ Archiving is reversible with --undo. Prefer it over closing a task whose work has moved elsewhere: closing asserts a status the task never reached, and not every list even has a status named "closed".`, Args: cobra.ExactArgs(1), + // API failures are not usage errors; don't bury them under the help text. + SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { taskID := args[0] undo, _ := cmd.Flags().GetBool("undo") + verb, action := "Archived", "archive" + if undo { + verb, action = "Unarchived", "unarchive" + } + client, err := api.NewClient() if err != nil { - return err + return fmt.Errorf("failed to create API client: %w", err) } task, err := client.SetTaskArchived(context.Background(), taskID, !undo) if err != nil { - return err - } - - verb := "Archived" - if undo { - verb = "Unarchived" + return fmt.Errorf("failed to %s task: %w", action, err) } if outputFormat != "table" { @@ -760,8 +762,10 @@ func init() { taskUpdateCmd.Flags().StringSlice("add-assignee", []string{}, "Add assignees (username or ID)") taskUpdateCmd.Flags().StringSlice("remove-assignee", []string{}, "Remove assignees (username or ID)") - // Reopen command flags + // Archive command flags taskArchiveCmd.Flags().Bool("undo", false, "Unarchive instead of archiving") + + // Reopen command flags taskCloseCmd.Flags().StringP("status", "s", "", "Status to set (default: the list's done status)") taskReopenCmd.Flags().StringP("status", "s", "", "Status to set (default: the list's first open status)") From 8471eef1b8f84371a496d10b5f08125576e460ab Mon Sep 17 00:00:00 2001 From: Tim Walsh Date: Sun, 15 Nov 2026 11:23:40 -0700 Subject: [PATCH 3/3] test(task): cover task archive request and command wiring Co-Authored-By: Claude Opus 5.5 --- internal/api/archive_test.go | 100 +++++++++++++++++++++++++++++++++++ internal/cmd/task_test.go | 15 ++++++ 2 files changed, 115 insertions(+) create mode 100644 internal/api/archive_test.go diff --git a/internal/api/archive_test.go b/internal/api/archive_test.go new file mode 100644 index 0000000..baa73d5 --- /dev/null +++ b/internal/api/archive_test.go @@ -0,0 +1,100 @@ +package api + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "net/url" + "testing" + "time" + + "github.com/raksul/go-clickup/clickup" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// newTestClient builds a Client whose SDK client talks to server instead of +// the real ClickUp API. +func newTestClient(t *testing.T, server *httptest.Server) *Client { + t.Helper() + + sdk := clickup.NewClient(server.Client(), "test-token") + baseURL, err := url.Parse(server.URL + "/") + require.NoError(t, err) + sdk.BaseURL = baseURL + + return &Client{ + client: sdk, + rateLimiter: NewRateLimiter(100, time.Minute), + } +} + +func TestSetTaskArchived(t *testing.T) { + tests := []struct { + name string + archived bool + }{ + {name: "archive", archived: true}, + {name: "undo", archived: false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var gotMethod, gotPath string + var gotBody map[string]any + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + gotMethod = r.Method + gotPath = r.URL.Path + raw, _ := io.ReadAll(r.Body) + _ = json.Unmarshal(raw, &gotBody) + + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"id":"abc123","name":"Retired task"}`)) + })) + defer server.Close() + + task, err := newTestClient(t, server).SetTaskArchived(context.Background(), "abc123", tt.archived) + require.NoError(t, err) + + assert.Equal(t, http.MethodPut, gotMethod) + assert.Equal(t, "/task/abc123", gotPath) + assert.Equal(t, map[string]any{"archived": tt.archived}, gotBody) + assert.Equal(t, "abc123", task.ID) + assert.Equal(t, "Retired task", task.Name) + }) + } +} + +func TestSetTaskArchived_NotFound(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusNotFound) + _, _ = w.Write([]byte(`{"err":"Task not found","ECODE":"ITEM_013"}`)) + })) + defer server.Close() + + task, err := newTestClient(t, server).SetTaskArchived(context.Background(), "missing", true) + assert.Error(t, err) + assert.Nil(t, task) +} + +func TestSetTaskArchived_EscapesTaskID(t *testing.T) { + var gotRawPath string + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + gotRawPath = r.URL.EscapedPath() + _, _ = w.Write([]byte(`{"id":"a/b"}`)) + })) + defer server.Close() + + _, err := newTestClient(t, server).SetTaskArchived(context.Background(), "a/b", true) + require.NoError(t, err) + assert.Equal(t, "/task/a%2Fb", gotRawPath) +} + +func TestSetTaskArchived_RequiresTaskID(t *testing.T) { + _, err := (&Client{}).SetTaskArchived(context.Background(), "", true) + assert.Error(t, err) +} diff --git a/internal/cmd/task_test.go b/internal/cmd/task_test.go index 83d1ccd..7b5b056 100644 --- a/internal/cmd/task_test.go +++ b/internal/cmd/task_test.go @@ -8,6 +8,7 @@ import ( "github.com/raksul/go-clickup/clickup" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTaskCommands_Structure(t *testing.T) { @@ -68,6 +69,20 @@ func TestTaskCommands_Structure(t *testing.T) { assert.NotNil(t, taskReopenCmd) assert.NotNil(t, taskSearchCmd) }) + + // Test task archive command + t.Run("task archive command", func(t *testing.T) { + cmd, _, err := taskCmd.Find([]string{"archive"}) + require.NoError(t, err) + assert.Same(t, taskArchiveCmd, cmd) + assert.NotNil(t, cmd.RunE) + assert.True(t, cmd.SilenceUsage) + + undo := cmd.Flags().Lookup("undo") + require.NotNil(t, undo) + assert.Equal(t, "bool", undo.Value.Type()) + assert.Equal(t, "false", undo.DefValue) + }) } // Test helper functions