Skip to content

Add label create, update, and delete operations#59

Open
wesnick wants to merge 1 commit into
mainfrom
claude/label-management-46apjy
Open

Add label create, update, and delete operations#59
wesnick wants to merge 1 commit into
mainfrom
claude/label-management-46apjy

Conversation

@wesnick

@wesnick wesnick commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Implements full CRUD operations for Gmail labels via the gwcli labels command group. Users can now create, update (rename/change visibility), and delete labels in addition to the existing list/apply/remove operations.

Changes

  • New command handlers (labels.go):

    • runLabelsCreate() - Create a new user label with optional visibility settings
    • runLabelsUpdate() - Rename a label or change its message/label list visibility
    • runLabelsDelete() - Permanently delete a user label (requires --force flag)
  • New connection methods (pkg/gwcli/connection.go):

    • CreateLabel() - Calls gmail.Users.Labels.Create API
    • UpdateLabel() - Calls gmail.Users.Labels.Patch API
    • DeleteLabel() - Calls gmail.Users.Labels.Delete API
    • invalidateLabels() - Clears label cache after mutations so subsequent operations reload from API
    • Initialize messageCache and labelCache in NewFake() for testing
  • CLI command definitions (main.go):

    • labels create <name> - Create label with optional --message-list-visibility and --label-list-visibility flags
    • labels update <label-id> - Update label by name or ID with optional --name, --message-list-visibility, --label-list-visibility flags
    • labels delete <label-id> - Delete label by name or ID, requires --force flag
  • Comprehensive test suite (labels_test.go):

    • TestRunLabelsCreate - Verify label creation with JSON output
    • TestRunLabelsCreateEmptyName - Reject empty label names
    • TestRunLabelsCreateDuplicate - Reject duplicate names (case-insensitive)
    • TestRunLabelsUpdate - Verify label rename with name resolution
    • TestRunLabelsUpdateNoChanges - Reject updates with no fields provided
    • TestRunLabelsDelete - Verify label deletion with JSON output
    • TestRunLabelsDeleteRequiresForce - Require --force flag
    • TestRunLabelsDeleteSystemLabel - Prevent deletion of system labels (INBOX, SENT, etc.)
  • Documentation (CLAUDE.md):

    • Updated label operations section with new commands and implementation details
    • Documented visibility flag mappings and safety features

Implementation Details

  • Duplicate detection: create checks existing labels case-insensitively before creating
  • System label protection: delete prevents removal of Gmail system labels (type="system") with a clear error message
  • Label resolution: Both update and delete accept label name or ID, resolved via the shared resolveLabelID() helper
  • Cache invalidation: All mutations call invalidateLabels() to ensure subsequent operations see fresh data from the API
  • Visibility flags: Map to Gmail API fields:
    • --message-list-visibility: show or hide
    • --label-list-visibility: labelShow, labelShowIfUnread, or labelHide
  • Output formats: All operations support both JSON (--json) and human-readable text output
  • Safety: delete requires explicit --force flag (non-interactive rule Refactor app into single root command #3 from CLAUDE.md)

https://claude.ai/code/session_01UdqRpUFcLqZQjFpDDkbnxk

gwcli previously only listed/applied/removed labels; creation and deletion
required the Gmail UI. Add imperative label CRUD via the Gmail
users.labels API:

- labels create <name>   — create a user label (rejects duplicates),
  with --message-list-visibility / --label-list-visibility flags and
  '/'-nested names
- labels update <label>  — rename and/or change visibility
- labels delete <label>  — delete a user label (--force required,
  refuses system labels)

create/update/delete accept a label name or ID via the shared
resolveLabelID helper, and any mutation invalidates the connection's
label cache. The gmail.labels OAuth scope already requested covers all
of this.

Also fix two pre-existing dispatch bugs where "labels apply" and
"labels remove" never matched because Kong includes the <label-id> arg
placeholder in the command string. Initialize the label/message caches
in NewFake so LoadLabels works under test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UdqRpUFcLqZQjFpDDkbnxk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants