From 0aeeacf7f579ed646725aaa88ed09af4712b5315 Mon Sep 17 00:00:00 2001 From: Rolf Timmermans Date: Mon, 28 Oct 2024 15:56:10 +0100 Subject: [PATCH] Allow using aliases. --- CHANGELOG.md | 4 ++++ README.md | 6 +++--- cmd/root.go | 18 ++++++++++++++++++ kbuild | 1 + kctl | 1 + kdeploy | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) create mode 120000 kbuild create mode 120000 kctl create mode 120000 kdeploy diff --git a/CHANGELOG.md b/CHANGELOG.md index c0a3f9e4..bc953513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v2.3.0 + +* Introduce aliases `kbuild` for `kd build`, `kdeploy` for `kd deploy` and `kctl` for `kd ctl`. + # v2.2.1 * Fix issues that prevented the `kd ctl` command from working. diff --git a/README.md b/README.md index 4eb36ee4..26028512 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ 1. Ensure you have `~/.bin` directory or similar that is in your `$PATH` 2. Install KD: -- When using an Apple M1+ Mac run: `rm -f ~/.bin/kd && curl -L $(curl -s https://api.github.com/repos/voormedia/kd/releases/latest | grep browser_download_url | grep darwin_arm64 | cut -d '"' -f 4) -o ~/.bin/kd && chmod +x ~/.bin/kd` -- When using an Intel Mac run: `rm -f ~/.bin/kd && curl -L $(curl -s https://api.github.com/repos/voormedia/kd/releases/latest | grep browser_download_url | grep darwin_amd64 | cut -d '"' -f 4) -o ~/.bin/kd && chmod +x ~/.bin/kd` +- When using an Apple M1+ Mac run: `rm -f ~/.bin/kd && curl -L $(curl -s https://api.github.com/repos/voormedia/kd/releases/latest | grep browser_download_url | grep darwin_arm64 | cut -d '"' -f 4) -o ~/.bin/kd && chmod +x ~/.bin/kd && ln -sf ~/.bin/kd ~/.bin/kbuild && ln -sf ~/.bin/kd ~/.bin/kdeploy && ln -sf ~/.bin/kd ~/.bin/kctl` +- When using an Intel Mac run: `rm -f ~/.bin/kd && curl -L $(curl -s https://api.github.com/repos/voormedia/kd/releases/latest | grep browser_download_url | grep darwin_amd64 | cut -d '"' -f 4) -o ~/.bin/kd && chmod +x ~/.bin/kd && ln -sf ~/.bin/kd ~/.bin/kbuild && ln -sf ~/.bin/kd ~/.bin/kdeploy && ln -sf ~/.bin/kd ~/.bin/kctl` 3. Install Google Cloud credential helper: @@ -36,7 +36,7 @@ example, to expose the SSH key `id_ed25519` to `kd`, execute the following: `ssh-add ~/.ssh/id_ed25519` -In case your .ssh folder does not contain the file `id_ed25519` but `id_rsa`, use the following command: +In case your .ssh folder does not contain the file `id_ed25519` but `id_rsa`, use the following command: `ssh-add ~/.ssh/id_rsa` diff --git a/cmd/root.go b/cmd/root.go index 9de6a4fc..c13c5368 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,9 @@ package cmd import ( + "os" + "path/filepath" + "github.com/spf13/cobra" "github.com/voormedia/kd/pkg/util" ) @@ -23,6 +26,21 @@ func init() { cmdRoot.PersistentFlags().Bool("verbose", false, "verbose output") } +func setCommand(cmdRoot *cobra.Command, command string) { + cmdRoot.SetArgs(append([]string{command}, os.Args[1:]...)) +} + func Execute() { + executableName := filepath.Base(os.Args[0]) + + switch executableName { + case "kbuild": + setCommand(cmdRoot, "build") + case "kctl": + setCommand(cmdRoot, "ctl") + case "kdeploy": + setCommand(cmdRoot, "deploy") + } + cmdRoot.Execute() } diff --git a/kbuild b/kbuild new file mode 120000 index 00000000..5c9096ae --- /dev/null +++ b/kbuild @@ -0,0 +1 @@ +kd \ No newline at end of file diff --git a/kctl b/kctl new file mode 120000 index 00000000..5c9096ae --- /dev/null +++ b/kctl @@ -0,0 +1 @@ +kd \ No newline at end of file diff --git a/kdeploy b/kdeploy new file mode 120000 index 00000000..5c9096ae --- /dev/null +++ b/kdeploy @@ -0,0 +1 @@ +kd \ No newline at end of file