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

[WIP] feat: revamp harbor cli #4

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 26 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish Release

on:
push:
tags:
- v*

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup go env
uses: actions/setup-go@master
with:
go-version: "1.20"
- name: goreleaser with tag
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

# Go workspace file
go.work
/bin

# harbor compiled file
harbor
/harbor
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

Harbor follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
Empty file added CONTRIBUTING.md
Empty file.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
GITCOMMIT := $(shell git rev-parse --short=8 HEAD)
PROJECT_PKG = github.com/goharbor/harbor-cli
RELEASE_CHANNEL="edge"
LDFLAGS = "-w -s -X $(PROJECT_PKG)/version.GitCommit=$(GITCOMMIT) -X $(PROJECT_PKG)/version.ReleaseChannel=$(RELEASE_CHANNEL)"
ARCH := amd64
GO_EXE = go

make:
gofmt -l -s -w .
go build -ldflags=${LDFLAGS} -o harbor cmd/harbor/main.go

windows:
go build -ldflags=${LDFLAGS} -o harbor.exe cmd/harbor/main.go

.PHONY: build-win-amd64
build-win-amd64: ## build for windows amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=windows $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-windows-$(ARCH).exe ./cmd/harbor/main.go
.PHONY: build-linux-amd64
build-linux-amd64: ## build for linux amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=linux $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-linux-$(ARCH) ./cmd/harbor/main.go

.PHONY: build-darwin-amd64
build-darwin-amd64: ## build for darwin amd64
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=darwin $(GO_EXE) build -v --ldflags=$(LDFLAGS) \
-o bin/harbor-darwin-$(ARCH) ./cmd/harbor/main.go

.PHONY: clean
clean:
rm -rf bin

.PHONY: lint
lint:
golangci-lint run --timeout 5m
14 changes: 14 additions & 0 deletions cmd/harbor/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"github.com/goharbor/harbor-cli/cmd/harbor/root"
)

func main() {
err := root.New().Execute()
if err != nil {
os.Exit(1)
}
}
49 changes: 23 additions & 26 deletions cmd/root.go → cmd/harbor/root/cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package cmd
package root

import (
"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/login"
"github.com/akshatdalton/harbor-cli/cmd/project"
"github.com/akshatdalton/harbor-cli/cmd/registry"
"github.com/goharbor/harbor-cli/cmd/harbor/root/project"
"github.com/goharbor/harbor-cli/cmd/harbor/root/registry"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +16,8 @@ func newGetCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewGetProjectCommand())
cmd.AddCommand(registry.NewGetRegistryCommand())
cmd.AddCommand(project.GetProjectCommand())
cmd.AddCommand(registry.GetRegistryCommand())
return cmd
}

Expand All @@ -31,8 +30,8 @@ func newListCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewListProjectCommand())
cmd.AddCommand(registry.NewListRegistryCommand())
cmd.AddCommand(project.ListProjectCommand())
cmd.AddCommand(registry.ListRegistryCommand())
return cmd
}

Expand All @@ -45,8 +44,8 @@ func newCreateCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewCreateProjectCommand())
cmd.AddCommand(registry.NewCreateRegistryCommand())
cmd.AddCommand(project.CreateProjectCommand())
cmd.AddCommand(registry.CreateRegistryCommand())
return cmd
}

Expand All @@ -59,8 +58,8 @@ func newDeleteCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(project.NewDeleteProjectCommand())
cmd.AddCommand(registry.NewDeleteRegistryCommand())
cmd.AddCommand(project.DeleteProjectCommand())
cmd.AddCommand(registry.DeleteRegistryCommand())
return cmd
}

Expand All @@ -73,26 +72,24 @@ func newUpdateCommand() *cobra.Command {
}

cmd.PersistentFlags().String(constants.CredentialNameOption, "", constants.CredentialNameHelp)
cmd.AddCommand(registry.NewUpdateRegistryCommand())
cmd.AddCommand(registry.UpdateRegistryCommand())
return cmd
}

func addCommands(cmd *cobra.Command) {
cmd.AddCommand(login.NewLoginCommand())
cmd.AddCommand(newGetCommand())
cmd.AddCommand(newListCommand())
cmd.AddCommand(newCreateCommand())
cmd.AddCommand(newDeleteCommand())
cmd.AddCommand(newUpdateCommand())
}

// CreateHarborCLI creates a new Harbor CLI
func CreateHarborCLI() *cobra.Command {
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "harbor",
Use: "harbor [command]",
Short: "Official Harbor CLI",
}

addCommands(cmd)
cmd.AddCommand(
LoginCommand(),
newGetCommand(),
newListCommand(),
newCreateCommand(),
newDeleteCommand(),
newUpdateCommand(),
)
return cmd
}
8 changes: 4 additions & 4 deletions cmd/login/login.go → cmd/harbor/root/login.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package login
package root

import (
"context"
"fmt"

"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/harbor"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/user"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +17,8 @@ type loginOptions struct {
password string
}

// NewLoginCommand creates a new `harbor login` command
func NewLoginCommand() *cobra.Command {
// LoginCommand creates a new `harbor login` command
func LoginCommand() *cobra.Command {
var opts loginOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -17,8 +17,8 @@ type createProjectOptions struct {
storageLimit int64
}

// NewCreateProjectCommand creates a new `harbor create project` command
func NewCreateProjectCommand() *cobra.Command {
// CreateProjectCommand creates a new `harbor create project` command
func CreateProjectCommand() *cobra.Command {
var opts createProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

type deleteProjectOptions struct {
projectNameOrID string
}

// NewDeleteProjectCommand creates a new `harbor delete project` command
func NewDeleteProjectCommand() *cobra.Command {
// DeleteProjectCommand creates a new `harbor delete project` command
func DeleteProjectCommand() *cobra.Command {
var opts deleteProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +21,7 @@ type listProjectOptions struct {
}

// NewListProjectCommand creates a new `harbor list project` command
func NewListProjectCommand() *cobra.Command {
func ListProjectCommand() *cobra.Command {
var opts listProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package project
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/project"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

type getProjectOptions struct {
projectNameOrID string
}

// NewGetProjectCommand creates a new `harbor get project` command
func NewGetProjectCommand() *cobra.Command {
// GetProjectCommand creates a new `harbor get project` command
func GetProjectCommand() *cobra.Command {
var opts getProjectOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package registry
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -24,7 +24,7 @@ type createRegistrytOptions struct {
}

// NewCreateRegistryCommand creates a new `harbor create registry` command
func NewCreateRegistryCommand() *cobra.Command {
func CreateRegistryCommand() *cobra.Command {
var opts createRegistrytOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strconv"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -16,7 +16,7 @@ type deleteRegistryOptions struct {
}

// NewDeleteRegistryCommand creates a new `harbor delete registry` command
func NewDeleteRegistryCommand() *cobra.Command {
func DeleteRegistryCommand() *cobra.Command {
var opts deleteRegistryOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package registry
import (
"context"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -17,7 +17,7 @@ type listRegistryOptions struct {
}

// NewListRegistryCommand creates a new `harbor list registry` command
func NewListRegistryCommand() *cobra.Command {
func ListRegistryCommand() *cobra.Command {
var opts listRegistryOptions

cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"strconv"

"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/akshatdalton/harbor-cli/cmd/utils"
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/registry"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/goharbor/harbor-cli/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +27,7 @@ type updateRegistrytOptions struct {
}

// NewUpdateRegistryCommand creates a new `harbor update registry` command
func NewUpdateRegistryCommand() *cobra.Command {
func UpdateRegistryCommand() *cobra.Command {
var opts updateRegistrytOptions

cmd := &cobra.Command{
Expand Down
Loading