Skip to content

Commit

Permalink
feat: add version and update command (#13)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Pradumnasaraf authored Aug 27, 2024
1 parent 76d6a11 commit c5c314b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!-- Add notes to reviewers if applicable -->

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions cmd/updateCmd.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions cmd/versionCmd.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c5c314b

Please sign in to comment.