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

feat: Add ping command to check Harbor connectivity #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 cmd/harbor/root/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ harbor help
HealthCommand(),
schedule.Schedule(),
labels.Labels(),
PingCommand(),
)

return root
Expand Down
34 changes: 34 additions & 0 deletions cmd/harbor/root/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package root

import (
"fmt"

"github.com/goharbor/harbor-cli/pkg/api"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func PingCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ping",
Short: "Ping the Harbor server",
Long: `Check connectivity to the Harbor server. Returns an error if Harbor is unreachable.`,
Example: ` harbor ping

# Example usage with verbose output
harbor ping -v
`,
RunE: func(cmd *cobra.Command, args []string) error {
err := api.Ping()
if err != nil {
log.Errorf("Failed to ping Harbor: %v", err)
return err
}

fmt.Println("Pong! Successfully contacted the Harbor server.")
return nil
},
}

return cmd
}
Binary file added harbor-cli
Binary file not shown.