Skip to content

Commit

Permalink
move commands into pkg/
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Nov 1, 2019
1 parent a8a3086 commit 886f559
Show file tree
Hide file tree
Showing 26 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ INSTALL?=install
INSTALL_DIR?=$(shell hack/build/goinstalldir.sh)
# record the source commit in the binary
COMMIT?=$(shell git rev-parse HEAD 2>/dev/null)
LD_FLAGS:=-X sigs.k8s.io/kind/cmd/kind/version.GitCommit=$(COMMIT)
LD_FLAGS:=-X sigs.k8s.io/kind/pkg/cmd/kind/version.GitCommit=$(COMMIT)
# the output binary name, overridden when cross compiling
KIND_BINARY_NAME?=kind

Expand Down
21 changes: 21 additions & 0 deletions cmd/kind/app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app

import (
"os"

"sigs.k8s.io/kind/pkg/cmd/kind"
)

// Main is the kind main(), it will invoke Run(), if an error is returned
// it will then call os.Exit
func Main() {
if err := Run(); err != nil {
os.Exit(1)
}
}

// Run invokes the kind root command, returning the error.
// See: sigs.k8s.io/kind/pkg/cmd/kind
func Run() error {
return kind.NewCommand().Execute()
}
9 changes: 9 additions & 0 deletions cmd/kind/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"sigs.k8s.io/kind/cmd/kind/app"
)

func main() {
app.Main()
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License.
package main

import (
"sigs.k8s.io/kind/cmd/kind"
"sigs.k8s.io/kind/cmd/kind/app"
)

func main() {
kind.Main()
app.Main()
}
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/kind/build/build.go → pkg/cmd/kind/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package build
import (
"github.com/spf13/cobra"

"sigs.k8s.io/kind/cmd/kind/build/baseimage"
"sigs.k8s.io/kind/cmd/kind/build/nodeimage"
"sigs.k8s.io/kind/pkg/cmd/kind/build/baseimage"
"sigs.k8s.io/kind/pkg/cmd/kind/build/nodeimage"
)

// NewCommand returns a new cobra.Command for building
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package completion
import (
"github.com/spf13/cobra"

"sigs.k8s.io/kind/cmd/kind/completion/bash"
"sigs.k8s.io/kind/cmd/kind/completion/zsh"
"sigs.k8s.io/kind/pkg/cmd/kind/completion/bash"
"sigs.k8s.io/kind/pkg/cmd/kind/completion/zsh"
)

// NewCommand returns a new cobra.Command for cluster creation
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package create
import (
"github.com/spf13/cobra"

createcluster "sigs.k8s.io/kind/cmd/kind/create/cluster"
createcluster "sigs.k8s.io/kind/pkg/cmd/kind/create/cluster"
)

// NewCommand returns a new cobra.Command for cluster creation
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package delete
import (
"github.com/spf13/cobra"

deletecluster "sigs.k8s.io/kind/cmd/kind/delete/cluster"
deletecluster "sigs.k8s.io/kind/pkg/cmd/kind/delete/cluster"
)

// NewCommand returns a new cobra.Command for cluster creation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package export
import (
"github.com/spf13/cobra"

"sigs.k8s.io/kind/cmd/kind/export/logs"
"sigs.k8s.io/kind/pkg/cmd/kind/export/logs"
)

// NewCommand returns a new cobra.Command for export
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/kind/get/get.go → pkg/cmd/kind/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package get
import (
"github.com/spf13/cobra"

"sigs.k8s.io/kind/cmd/kind/get/clusters"
"sigs.k8s.io/kind/cmd/kind/get/kubeconfig"
"sigs.k8s.io/kind/cmd/kind/get/nodes"
"sigs.k8s.io/kind/pkg/cmd/kind/get/clusters"
"sigs.k8s.io/kind/pkg/cmd/kind/get/kubeconfig"
"sigs.k8s.io/kind/pkg/cmd/kind/get/nodes"
)

// NewCommand returns a new cobra.Command for get
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/kind/load/load.go → pkg/cmd/kind/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package load
import (
"github.com/spf13/cobra"

dockerimage "sigs.k8s.io/kind/cmd/kind/load/docker-image"
imagearchive "sigs.k8s.io/kind/cmd/kind/load/image-archive"
dockerimage "sigs.k8s.io/kind/pkg/cmd/kind/load/docker-image"
imagearchive "sigs.k8s.io/kind/pkg/cmd/kind/load/image-archive"
)

// NewCommand returns a new cobra.Command for get
Expand Down
35 changes: 13 additions & 22 deletions cmd/kind/kind.go → pkg/cmd/kind/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (

"github.com/spf13/cobra"

"sigs.k8s.io/kind/cmd/kind/build"
"sigs.k8s.io/kind/cmd/kind/completion"
"sigs.k8s.io/kind/cmd/kind/create"
"sigs.k8s.io/kind/cmd/kind/delete"
"sigs.k8s.io/kind/cmd/kind/export"
"sigs.k8s.io/kind/cmd/kind/get"
"sigs.k8s.io/kind/cmd/kind/load"
"sigs.k8s.io/kind/cmd/kind/version"
"sigs.k8s.io/kind/pkg/cmd/kind/build"
"sigs.k8s.io/kind/pkg/cmd/kind/completion"
"sigs.k8s.io/kind/pkg/cmd/kind/create"
"sigs.k8s.io/kind/pkg/cmd/kind/delete"
"sigs.k8s.io/kind/pkg/cmd/kind/export"
"sigs.k8s.io/kind/pkg/cmd/kind/get"
"sigs.k8s.io/kind/pkg/cmd/kind/load"
"sigs.k8s.io/kind/pkg/cmd/kind/version"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/globals"
Expand All @@ -52,7 +52,11 @@ func NewCommand() *cobra.Command {
Short: "kind is a tool for managing local Kubernetes clusters",
Long: "kind creates and manages local Kubernetes clusters using Docker container 'nodes'",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return runE(flags, cmd)
err := runE(flags, cmd)
if err != nil {
logError(err)
}
return err
},
SilenceUsage: true,
SilenceErrors: true,
Expand Down Expand Up @@ -115,19 +119,6 @@ func runE(flags *Flags, cmd *cobra.Command) error {
return nil
}

// Run runs the `kind` root command
func Run() error {
return NewCommand().Execute()
}

// Main wraps Run and sets the log formatter
func Main() {
if err := Run(); err != nil {
logError(err)
os.Exit(1)
}
}

// logError logs the error and the root stacktrace if there is one
func logError(err error) {
globals.GetLogger().Errorf("ERROR: %v", err)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 886f559

Please sign in to comment.