From 553fa62858055ca9697ded723228895dc36f0d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Din=20Mu=C5=A1i=C4=87?= Date: Sat, 13 Apr 2024 20:35:25 +0200 Subject: [PATCH] Move commands to cmd dir (#188) * cmd: Move cmd directory out of pkg Signed-off-by: Din Music * github: Update build commands Signed-off-by: Din Music * docs: Update required go version and build command Signed-off-by: Din Music --------- Signed-off-by: Din Music --- .github/actions/runner-setup/action.yml | 2 +- .github/workflows/release-binaries.yml | 6 +-- {pkg/cmd => cmd}/cmd.go | 2 +- {pkg/cmd => cmd}/cmd_apply.go | 6 +-- {pkg/cmd => cmd}/cmd_destroy.go | 2 +- {pkg/cmd => cmd}/cmd_export.go | 2 +- {pkg/cmd => cmd}/cmd_export_config.go | 2 +- {pkg/cmd => cmd}/cmd_export_kubeconfig.go | 4 +- {pkg/cmd => cmd}/cmd_export_preset.go | 4 +- {pkg/cmd => cmd}/cmd_list.go | 2 +- {pkg/cmd => cmd}/cmd_list_clusters.go | 4 +- {pkg/cmd => cmd}/cmd_list_presets.go | 2 +- {pkg/cmd => cmd}/cmd_test.go | 2 +- main.go => cmd/main.go | 7 ++- {pkg/cmd => cmd}/meta_clusters.go | 2 +- {pkg/cmd => cmd}/meta_clusters_test.go | 2 +- {pkg/cmd => cmd}/utils.go | 2 +- {pkg/cmd => cmd}/utils_test.go | 2 +- doc.go | 49 ------------------- .../other/local-development.md | 4 +- 20 files changed, 29 insertions(+), 79 deletions(-) rename {pkg/cmd => cmd}/cmd.go (98%) rename {pkg/cmd => cmd}/cmd_apply.go (99%) rename {pkg/cmd => cmd}/cmd_destroy.go (99%) rename {pkg/cmd => cmd}/cmd_export.go (98%) rename {pkg/cmd => cmd}/cmd_export_config.go (99%) rename {pkg/cmd => cmd}/cmd_export_kubeconfig.go (99%) rename {pkg/cmd => cmd}/cmd_export_preset.go (99%) rename {pkg/cmd => cmd}/cmd_list.go (97%) rename {pkg/cmd => cmd}/cmd_list_clusters.go (98%) rename {pkg/cmd => cmd}/cmd_list_presets.go (98%) rename {pkg/cmd => cmd}/cmd_test.go (99%) rename main.go => cmd/main.go (65%) rename {pkg/cmd => cmd}/meta_clusters.go (99%) rename {pkg/cmd => cmd}/meta_clusters_test.go (99%) rename {pkg/cmd => cmd}/utils.go (98%) rename {pkg/cmd => cmd}/utils_test.go (98%) delete mode 100644 doc.go diff --git a/.github/actions/runner-setup/action.yml b/.github/actions/runner-setup/action.yml index 7c13fd86..996ae993 100644 --- a/.github/actions/runner-setup/action.yml +++ b/.github/actions/runner-setup/action.yml @@ -35,6 +35,6 @@ runs: - name: Build Kubitect shell: bash run: | - go build -ldflags "-s -w" -trimpath . + go build -ldflags "-s -w" -trimpath -o kubitect ./cmd sudo mv kubitect /usr/local/bin/kubitect kubitect --version diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index 8dd2f029..e2857ea9 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -23,8 +23,6 @@ jobs: exclude: - goarch: "386" goos: darwin - env: - go-version: 1.21 steps: - name: Checkout uses: actions/checkout@v4 @@ -36,5 +34,7 @@ jobs: extra_files: LICENSE goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} - goversion: ${{ env.go-version }} + goversion: go.mod github_token: ${{ github.token }} + project_path: ./cmd + diff --git a/pkg/cmd/cmd.go b/cmd/cmd.go similarity index 98% rename from pkg/cmd/cmd.go rename to cmd/cmd.go index 75ab0530..0a2b2996 100644 --- a/pkg/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "github.com/MusicDin/kubitect/pkg/env" diff --git a/pkg/cmd/cmd_apply.go b/cmd/cmd_apply.go similarity index 99% rename from pkg/cmd/cmd_apply.go rename to cmd/cmd_apply.go index d886e20b..e6b9d82b 100644 --- a/pkg/cmd/cmd_apply.go +++ b/cmd/cmd_apply.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "github.com/MusicDin/kubitect/pkg/app" @@ -18,10 +18,10 @@ var ( applyExample = Example(` Create a new cluster or modify an existing one: > kubitect apply --config cluster.yaml - + To upgrade an existing cluster, bump the Kubernetes version in current cluster config and run: > kubitect apply --config cluster.yaml --action upgrade - + To scale an existing cluster, add or remove node instances in current cluster config and run: > kubitect apply --config cluster.yaml --action scale`) ) diff --git a/pkg/cmd/cmd_destroy.go b/cmd/cmd_destroy.go similarity index 99% rename from pkg/cmd/cmd_destroy.go rename to cmd/cmd_destroy.go index ca43b679..e5cb548c 100644 --- a/pkg/cmd/cmd_destroy.go +++ b/cmd/cmd_destroy.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" diff --git a/pkg/cmd/cmd_export.go b/cmd/cmd_export.go similarity index 98% rename from pkg/cmd/cmd_export.go rename to cmd/cmd_export.go index c9b04075..6cbe4b1d 100644 --- a/pkg/cmd/cmd_export.go +++ b/cmd/cmd_export.go @@ -1,4 +1,4 @@ -package cmd +package main import "github.com/spf13/cobra" diff --git a/pkg/cmd/cmd_export_config.go b/cmd/cmd_export_config.go similarity index 99% rename from pkg/cmd/cmd_export_config.go rename to cmd/cmd_export_config.go index 5e1f8608..57b4ce08 100644 --- a/pkg/cmd/cmd_export_config.go +++ b/cmd/cmd_export_config.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" diff --git a/pkg/cmd/cmd_export_kubeconfig.go b/cmd/cmd_export_kubeconfig.go similarity index 99% rename from pkg/cmd/cmd_export_kubeconfig.go rename to cmd/cmd_export_kubeconfig.go index b213777b..f3ad3a39 100644 --- a/pkg/cmd/cmd_export_kubeconfig.go +++ b/cmd/cmd_export_kubeconfig.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" @@ -18,7 +18,7 @@ var ( exportKcExample = Example(` To save a kubeconfig to the specific file, redirect command output to that file: > kubitect export kubeconfig --cluster lake > lake.yaml - + Use kubeconfig with kubectl to access cluster: > kubectl --kubeconfig lake.yaml get nodes`) ) diff --git a/pkg/cmd/cmd_export_preset.go b/cmd/cmd_export_preset.go similarity index 99% rename from pkg/cmd/cmd_export_preset.go rename to cmd/cmd_export_preset.go index 41520bff..f3acfe14 100644 --- a/pkg/cmd/cmd_export_preset.go +++ b/cmd/cmd_export_preset.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" @@ -18,7 +18,7 @@ var ( exportPresetExample = Example(` To list available presets run: > kubitect list presets - + To export a preset to the specific file run: > kubitect export preset --name minimal > cluster.yaml`) ) diff --git a/pkg/cmd/cmd_list.go b/cmd/cmd_list.go similarity index 97% rename from pkg/cmd/cmd_list.go rename to cmd/cmd_list.go index a38fe85e..904d6934 100644 --- a/pkg/cmd/cmd_list.go +++ b/cmd/cmd_list.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "github.com/spf13/cobra" diff --git a/pkg/cmd/cmd_list_clusters.go b/cmd/cmd_list_clusters.go similarity index 98% rename from pkg/cmd/cmd_list_clusters.go rename to cmd/cmd_list_clusters.go index 479bbec5..cac5e3e7 100644 --- a/pkg/cmd/cmd_list_clusters.go +++ b/cmd/cmd_list_clusters.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "strings" @@ -12,7 +12,7 @@ import ( var ( listClustersShort = "List clusters" listClustersLong = LongDesc(` - Command list clusters lists all clusters including local clusters if + Command list clusters lists all clusters including local clusters if a current (working) directory is Kubitect project.`) listClusterExample = Example(` diff --git a/pkg/cmd/cmd_list_presets.go b/cmd/cmd_list_presets.go similarity index 98% rename from pkg/cmd/cmd_list_presets.go rename to cmd/cmd_list_presets.go index cd76d28f..9545a822 100644 --- a/pkg/cmd/cmd_list_presets.go +++ b/cmd/cmd_list_presets.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "github.com/MusicDin/kubitect/embed" diff --git a/pkg/cmd/cmd_test.go b/cmd/cmd_test.go similarity index 99% rename from pkg/cmd/cmd_test.go rename to cmd/cmd_test.go index 70adbb00..410df07a 100644 --- a/pkg/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "testing" diff --git a/main.go b/cmd/main.go similarity index 65% rename from main.go rename to cmd/main.go index 61e3962b..9ff416eb 100644 --- a/main.go +++ b/cmd/main.go @@ -1,14 +1,13 @@ package main import ( - "github.com/MusicDin/kubitect/pkg/cmd" - "github.com/MusicDin/kubitect/pkg/ui" "os" + + "github.com/MusicDin/kubitect/pkg/ui" ) func main() { - err := cmd.NewRootCmd().Execute() - + err := NewRootCmd().Execute() if err != nil { ui.PrintBlockE(err) os.Exit(1) diff --git a/pkg/cmd/meta_clusters.go b/cmd/meta_clusters.go similarity index 99% rename from pkg/cmd/meta_clusters.go rename to cmd/meta_clusters.go index 0cab6543..afe75869 100644 --- a/pkg/cmd/meta_clusters.go +++ b/cmd/meta_clusters.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" diff --git a/pkg/cmd/meta_clusters_test.go b/cmd/meta_clusters_test.go similarity index 99% rename from pkg/cmd/meta_clusters_test.go rename to cmd/meta_clusters_test.go index 3e6b7302..cdb6acfe 100644 --- a/pkg/cmd/meta_clusters_test.go +++ b/cmd/meta_clusters_test.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "os" diff --git a/pkg/cmd/utils.go b/cmd/utils.go similarity index 98% rename from pkg/cmd/utils.go rename to cmd/utils.go index 462f36bc..0e740918 100644 --- a/pkg/cmd/utils.go +++ b/cmd/utils.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" diff --git a/pkg/cmd/utils_test.go b/cmd/utils_test.go similarity index 98% rename from pkg/cmd/utils_test.go rename to cmd/utils_test.go index 8cb96363..e8a484b7 100644 --- a/pkg/cmd/utils_test.go +++ b/cmd/utils_test.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "testing" diff --git a/doc.go b/doc.go deleted file mode 100644 index d5a35ea9..00000000 --- a/doc.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -Package kubitect is a CLI tool that helps you manage multiple Kubernetes clusters. - -# Installation - -A valid installation of Go 1.18 or greater is required. The following example -installs the latest stable version of the Kubitect CLI. Replace latest with a -specific version tag to install other versions. - - go install github.com/MusicDin/kubitect/cmd/kubitect@latest - -You can download the binary from the https://github.com/MusicDin/kubitect/releases -page and add it to the $PATH environment variable, or move the binary file to a -directory such as /usr/local/bin/. - -# Usage - -After installation the `kubitect` command should be available for usage. - -example: - - kubitect --help - -Output: - - Kubitect is a CLI tool that helps you manage multiple Kubernetes clusters. - - Usage: - kubitect [command] - - Cluster Management Commands: - apply Create, scale or upgrade the cluster - destroy Destroy the cluster - - Support Commands: - export Export specific configuration file - list List Kubitect resources - - Other Commands: - completion Generate the autocompletion script for the specified shell - help Help about any command - - Flags: - -h, --help help for kubitect - -v, --version version for kubitect - - Use "kubitect [command] --help" for more information about a command. -*/ -package main diff --git a/docs/getting-started/other/local-development.md b/docs/getting-started/other/local-development.md index 33bdb833..88fd4100 100644 --- a/docs/getting-started/other/local-development.md +++ b/docs/getting-started/other/local-development.md @@ -9,7 +9,7 @@ This document shows how to build a CLI tool manually and how to use the project ## Prerequisites + [Git](https://git-scm.com/) -+ [Go 1.18](https://go.dev/dl/) or greater ++ [Go 1.22](https://go.dev/dl/) or greater ## Step 1: Clone the project @@ -28,7 +28,7 @@ cd kubitect The Kubitect CLI tool can be manually built using Go. Running the following command will produce a `kubitect` binary file. ```sh -go build . +go build -o kubitect ./cmd ``` To make the binary file globally accessible, move it to the `/usr/local/bin/` directory.