Skip to content

Commit c5c314b

Browse files
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
1 parent 76d6a11 commit c5c314b

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [ ] This PR does not contain plagiarized content.
1919
- [ ] The title of my pull request is a short description of the requested changes.
2020
- [ ] I have updated the documentation accordingly (if required).
21+
- [ ] Update the version of the `CliVersion` variable in `cmd/version.go` file (if their is a version change).
2122

2223
### 📄 Note to reviewers <!-- Add notes to reviewers if applicable -->
2324

.github/workflows/releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
github-token: ${{ secrets.PA_TOKEN }}
2020
output-file: "false"
2121
skip-commit: "true"
22-
22+
create-summary: 'true'
2323
outputs:
2424
tag: ${{ steps.changelog.outputs.tag }}
2525

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ Available Commands:
4949
help Help about any command
5050
image Know details about an image (Please put your question in quotes)
5151
search Ask a question and get a response (Please put your question in quotes)
52+
update Update gencli to the latest version
53+
version Know the installed version of gencli
5254

5355
Flags:
5456
-h, --help help for gencli
5557
```
5658

5759
> eg: gencli search "What is kubernetes" --words 525
60+
5861
> eg: gencli image "What is this image about?" --path /path/to/image.jpg --format jpg
5962
6063
### 📜 License

cmd/updateCmd.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// updateCmd represents the update command
11+
var updateCmd = &cobra.Command{
12+
Use: "update",
13+
Short: "Update gencli to the latest version",
14+
Long: `This command will help you to update gencli to the latest version.`,
15+
Run: func(cmd *cobra.Command, args []string) {
16+
update()
17+
},
18+
}
19+
20+
func update() {
21+
cmd := exec.Command("go", "install", "github.com/Pradumnasaraf/gencli@latest")
22+
_, err := cmd.Output()
23+
24+
if err != nil {
25+
fmt.Println("Error executing command:", err)
26+
return
27+
}
28+
29+
fmt.Printf("CLI updated successfully to the latest version (If any). Current version is: %s\n", CliVersion)
30+
}
31+
32+
func init() {
33+
rootCmd.AddCommand(updateCmd)
34+
}

cmd/versionCmd.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
const CliVersion = "v1.4.0"
10+
11+
// versionCmd represents the version command
12+
var versionCmd = &cobra.Command{
13+
Use: "version",
14+
Short: "Know the installed version of gencli",
15+
Long: `This command will help you to know the installed version of gencli`,
16+
Run: func(cmd *cobra.Command, args []string) {
17+
fmt.Println("gencli version:", CliVersion)
18+
},
19+
}
20+
21+
func init() {
22+
rootCmd.AddCommand(versionCmd)
23+
}

0 commit comments

Comments
 (0)