Skip to content

Commit

Permalink
feat: revamp harbor cli
Browse files Browse the repository at this point in the history
Signed-off-by: amands98 <amandeepsm.in@gmail.com>
  • Loading branch information
amands98 committed Jan 28, 2024
1 parent ec4cc6b commit 7345f6f
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 55 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -20,5 +20,4 @@
# Go workspace file
go.work

# harbor compiled file
harbor

3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -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.
Empty file added Dockerfile
Empty file.
3 changes: 3 additions & 0 deletions Makefile
@@ -0,0 +1,3 @@
make:
gofmt -l -s -w .
go build -o harbor cmd/harbor/main.go
14 changes: 14 additions & 0 deletions cmd/harbor/main.go
@@ -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)
}
}
31 changes: 14 additions & 17 deletions cmd/root.go → cmd/harbor/root/cmd.go
@@ -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 Down Expand Up @@ -77,22 +76,20 @@ func newUpdateCommand() *cobra.Command {
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
@@ -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
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
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
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
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
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
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
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 getRegistryOptions struct {
}

// NewGetRegistryCommand creates a new `harbor get registry` command
func NewGetRegistryCommand() *cobra.Command {
func GetRegistryCommand() *cobra.Command {
var opts getRegistryOptions

cmd := &cobra.Command{
Expand Down
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
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
1 change: 1 addition & 0 deletions doc/doc.md
@@ -0,0 +1 @@
We can create a worker function to automatically generate documents for users whenever a new release is available. This function will streamline the process of document generation and ensure that users have up-to-date information. By automating this task, we can improve efficiency and provide clear and concise documentation in a user-friendly manner. //@amands
2 changes: 1 addition & 1 deletion go.mod
@@ -1,4 +1,4 @@
module github.com/akshatdalton/harbor-cli
module github.com/goharbor/harbor-cli

go 1.20

Expand Down
File renamed without changes.
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"

"github.com/adrg/xdg"
"github.com/akshatdalton/harbor-cli/cmd/constants"
"github.com/goharbor/harbor-cli/pkg/constants"
"gopkg.in/yaml.v2"
)

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/e2e/test.md
@@ -0,0 +1 @@
e2e tests for cmd can slide in here

0 comments on commit 7345f6f

Please sign in to comment.