Skip to content

fix(labels): skip interactive form in label update when flags are set - #1108

Open
bhuvan-somisetty wants to merge 2 commits into
goharbor:mainfrom
bhuvan-somisetty:fix/label-update-non-interactive
Open

bhuvan-somisetty wants to merge 2 commits into
goharbor:mainfrom
bhuvan-somisetty:fix/label-update-non-interactive

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Oct 4, 2026 •

Copy link
Copy Markdown

Description

harbor label update always opened the interactive form, even when --name, --color or --description were passed. That made it impossible to use in scripts or CI: without a TTY the form fails and log.Fatal exits before the update is sent.

This PR applies the explicitly set flags directly and only opens the form when none of them are given, matching how harbor label create already behaves.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Added applyLabelUpdateFlags in cmd/harbor/root/labels/update.go, which copies the set update flags onto the label and reports whether any were set; update.UpdateLabelView now runs only when it returns false.
  • When flags are used, validateLabelUpdate rejects an empty --name or --color with an error, applying the same rules the interactive form enforces.
  • Removed the flags.Changed("scope") check, since label update never registers a --scope flag. Lookup flags (--global, --project, --project-id) don't count as updates.
  • Added cmd/harbor/root/labels/update_test.go, which tests the flag set and the flag-to-label mapping (no flags, single fields, clearing the description, all fields, lookup-only flags) and the empty name/color validation.

Testing

$ go test ./cmd/harbor/root/labels/
ok  	github.com/goharbor/harbor-cli/cmd/harbor/root/labels
$ go test ./...        # all packages pass
$ golangci-lint run ./...
0 issues.
$ cd doc && go run .   # regenerated docs, no diff (help text unchanged)

Usage after this change:

# non-interactive, no form shown
harbor label update demo-label --name demo-label-2 --color "#C92100" -d "updated"

# no update flags, form opens as before
harbor label update demo-label

harbor label update always opened the interactive form, even when
--name, --color or --description were passed, so the command could not
be used non-interactively and exited via log.Fatal without a TTY.

Apply the explicitly set flags and only fall back to the form when none
were given, matching label create. Also reject an empty --name and drop
the check for a --scope flag that update never registers.

Fixes goharbor#1107

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread cmd/harbor/root/labels/update.go
An explicit empty --color skipped the form's non-empty validation and
was sent to the API. Move the flag-path checks into validateLabelUpdate,
which rejects both an empty name and an empty color, and cover it with
unit tests.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>

This branch has not been deployed

No deployments
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.

[bug]: label update always opens interactive form and ignores --name/--color/--description flags

1 participant