Skip to content

Adds harbor context command#445

Merged
Vad1mo merged 21 commits into
goharbor:mainfrom
Darkhood148:context_command
May 20, 2025
Merged

Adds harbor context command#445
Vad1mo merged 21 commits into
goharbor:mainfrom
Darkhood148:context_command

Conversation

@Darkhood148

Copy link
Copy Markdown
Contributor

Related Issue:

#417

Description:

Adds harbor context command to manage and switch context by reading/writing from confg.yaml

@Darkhood148 Darkhood148 marked this pull request as draft April 25, 2025 07:36
@Darkhood148

Copy link
Copy Markdown
Contributor Author

image

@Vad1mo Vad1mo requested a review from Copilot April 29, 2025 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new harbor context command to manage and switch contexts by reading/writing from a configuration file.

  • Introduces a new command (harbor context list) for listing contexts
  • Adds a new view for rendering the context list
  • Creates additional API types to support the context functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/views/context/list/view.go Adds a view to render the list of contexts using a table
pkg/api/types.go Introduces the ContextListView type
cmd/harbor/root/context/list.go Implements the cobra command for listing contexts
cmd/harbor/root/context/cmd.go Adds a context command to the overall CLI command hierarchy
cmd/harbor/root/cmd.go Integrates the new context command into the root command collection
Comments suppressed due to low confidence (1)

cmd/harbor/root/context/list.go:38

  • [nitpick] Consider using named field initialization for ContextListView for improved clarity and maintainability (e.g., ContextListView{Name: cred.Name, Username: cred.Username, Server: cred.ServerAddress}).
cx := api.ContextListView{cred.Name, cred.Username, cred.ServerAddress}

Comment thread cmd/harbor/root/context/list.go Outdated
@Darkhood148

Copy link
Copy Markdown
Contributor Author

@Vad1mo Should I continue working on this and add harbor context switch command?

@Darkhood148 Darkhood148 marked this pull request as ready for review April 29, 2025 14:29
@Darkhood148

Copy link
Copy Markdown
Contributor Author

Hi @bupd
I have rename config to context as mentioned here: #438 . I have also improved the working of the list subcommand, giving it a neater ui. Can you review it please?

@bupd

bupd commented May 7, 2025

Copy link
Copy Markdown
Member

@Darkhood148 rebase onto main branch

@bupd bupd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Darkhood148 Thanks for your contributions

I have added some suggestion for improvements

Also rebase & run dagger call lint. and fix the lint issues

Thanks

Comment thread cmd/harbor/root/cmd.go Outdated
@Darkhood148 Darkhood148 force-pushed the context_command branch 6 times, most recently from 370ad74 to 844a9ae Compare May 8, 2025 16:46
@Darkhood148

Copy link
Copy Markdown
Contributor Author

@bupd Done the changes.

@bupd bupd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contributions

I have added suggestions please fix that.

Comment thread cmd/harbor/root/context/list.go
Comment thread test/e2e/config_cmd_test.go Outdated
@Darkhood148

Copy link
Copy Markdown
Contributor Author

Done with the changes @bupd !
The test was failing due to bubbletea opening a TTY by default which fails in non-interactive environments like Dagger and Github Workflows. As mentioned in the documentation, this can be disabled by adding:

if !term.IsTerminal(int(os.Stdout.Fd())) {
     opts = append(opts, tea.WithoutRenderer(), tea.WithInput(nil))
}

After adding this, the same test passes!
This could be useful while writing tests for other commands using bubbletea.

Comment thread harbor-cli Outdated
@Darkhood148 Darkhood148 force-pushed the context_command branch 3 times, most recently from 61908d1 to d2982a4 Compare May 13, 2025 13:12
@Vad1mo Vad1mo changed the title adds harbor context command Adds harbor context command May 13, 2025
@Vad1mo

Vad1mo commented May 13, 2025

Copy link
Copy Markdown
Member

It would make sense if the context listsub-command would display what is the current context.

Eg. with an Asterix

Image

@Vad1mo

Vad1mo commented May 13, 2025

Copy link
Copy Markdown
Member

context switch should allow switching context, just like currently harbor-cli login --name contextallows us to do so.

Furthermore, we should only have one way to switch the context, so we should remove harbor-cli login --name context

@Darkhood148

Copy link
Copy Markdown
Contributor Author

image

Darkhood148 and others added 19 commits May 19, 2025 20:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
@Vad1mo Vad1mo merged commit 89d1f40 into goharbor:main May 20, 2025
7 checks passed
@Vad1mo

Vad1mo commented May 20, 2025

Copy link
Copy Markdown
Member

Rename CurrentCredentialName: into CurrentContext

@Vad1mo

Vad1mo commented May 20, 2025

Copy link
Copy Markdown
Member

Mybe provide an output after context switch e..g switched context from x to y.

❯ ./harbor-cli context switch vadim2@goharbor-io
""

@Vad1mo

Vad1mo commented May 20, 2025

Copy link
Copy Markdown
Member

Display the current context in the UI

image

@Vad1mo

Vad1mo commented May 20, 2025

Copy link
Copy Markdown
Member

It would make more sense if the order of the list would not change and make the current context on the top:

image
image

rizul2108 pushed a commit to rizul2108/harbor-cli that referenced this pull request May 24, 2025
* adds harbor context command

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* Update cmd/harbor/root/context/list.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* renames config to context

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* linting changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* documentation changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* test changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* readd test; handle non-tty in bubble tea

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* highlight active user

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* adds context switch command

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates logging

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates context switch

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* Update cmd/harbor/root/context/delete.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* Update cmd/harbor/root/context/cmd.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* minor change

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebasing

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* doc changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* linting changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates docs

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

---------

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Darkhood148 added a commit to Darkhood148/harbor-cli that referenced this pull request May 27, 2025
* adds harbor context command

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* Update cmd/harbor/root/context/list.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* renames config to context

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* linting changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* documentation changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* test changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* readd test; handle non-tty in bubble tea

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebase and lint

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* highlight active user

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* adds context switch command

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates logging

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates context switch

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* Update cmd/harbor/root/context/delete.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* Update cmd/harbor/root/context/cmd.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>

* minor change

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* rebasing

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* doc changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* linting changes

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

* updates docs

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>

---------

Signed-off-by: Darkhood148 <ujjwal.sharma9999999@gmail.com>
Signed-off-by: Ujjwal Sharma <68021601+Darkhood148@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants