diff --git a/cmd/harbor/root/cmd.go b/cmd/harbor/root/cmd.go index 72b11eca..a30e38a0 100644 --- a/cmd/harbor/root/cmd.go +++ b/cmd/harbor/root/cmd.go @@ -82,6 +82,7 @@ harbor help HealthCommand(), schedule.Schedule(), labels.Labels(), + PingCommand(), ) return root diff --git a/cmd/harbor/root/ping.go b/cmd/harbor/root/ping.go new file mode 100644 index 00000000..a1382d25 --- /dev/null +++ b/cmd/harbor/root/ping.go @@ -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 +} diff --git a/harbor-cli b/harbor-cli new file mode 100755 index 00000000..b161a813 Binary files /dev/null and b/harbor-cli differ