From c5c314b50cd43cb2a85c2a8ff12649644df7b7a0 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Tue, 27 Aug 2024 23:59:33 +0530 Subject: [PATCH] feat: add version and update command (#13) - feat: add version and update command - docs: Update new command in README - chore: Update CliVersion variable in the `cmd/version.go` file - ci: Enable create-summary option in releases workflow --- .github/PULL_REQUEST_TEMPLATE.md | 1 + .github/workflows/releases.yml | 2 +- README.md | 3 +++ cmd/updateCmd.go | 34 ++++++++++++++++++++++++++++++++ cmd/versionCmd.go | 23 +++++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 cmd/updateCmd.go create mode 100644 cmd/versionCmd.go diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ac97fcc..0a4b378 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,6 +18,7 @@ - [ ] This PR does not contain plagiarized content. - [ ] The title of my pull request is a short description of the requested changes. - [ ] I have updated the documentation accordingly (if required). +- [ ] Update the version of the `CliVersion` variable in `cmd/version.go` file (if their is a version change). ### 📄 Note to reviewers diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index c56e970..c4bbc33 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -19,7 +19,7 @@ jobs: github-token: ${{ secrets.PA_TOKEN }} output-file: "false" skip-commit: "true" - + create-summary: 'true' outputs: tag: ${{ steps.changelog.outputs.tag }} diff --git a/README.md b/README.md index 4dbc8a4..ecd81e1 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,15 @@ Available Commands: help Help about any command image Know details about an image (Please put your question in quotes) search Ask a question and get a response (Please put your question in quotes) + update Update gencli to the latest version + version Know the installed version of gencli Flags: -h, --help help for gencli ``` > eg: gencli search "What is kubernetes" --words 525 + > eg: gencli image "What is this image about?" --path /path/to/image.jpg --format jpg ### 📜 License diff --git a/cmd/updateCmd.go b/cmd/updateCmd.go new file mode 100644 index 0000000..9a35316 --- /dev/null +++ b/cmd/updateCmd.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "fmt" + "os/exec" + + "github.com/spf13/cobra" +) + +// updateCmd represents the update command +var updateCmd = &cobra.Command{ + Use: "update", + Short: "Update gencli to the latest version", + Long: `This command will help you to update gencli to the latest version.`, + Run: func(cmd *cobra.Command, args []string) { + update() + }, +} + +func update() { + cmd := exec.Command("go", "install", "github.com/Pradumnasaraf/gencli@latest") + _, err := cmd.Output() + + if err != nil { + fmt.Println("Error executing command:", err) + return + } + + fmt.Printf("CLI updated successfully to the latest version (If any). Current version is: %s\n", CliVersion) +} + +func init() { + rootCmd.AddCommand(updateCmd) +} diff --git a/cmd/versionCmd.go b/cmd/versionCmd.go new file mode 100644 index 0000000..8dbdfbb --- /dev/null +++ b/cmd/versionCmd.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +const CliVersion = "v1.4.0" + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Know the installed version of gencli", + Long: `This command will help you to know the installed version of gencli`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("gencli version:", CliVersion) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}