Skip to content

Commit 1b72d0c

Browse files
feat: add version and update command (#28)
* feat: add version and update command * docs: Update PULL_REQUEST_TEMPLATE.md
1 parent c0f24c8 commit 1b72d0c

File tree

5 files changed

+47
-58
lines changed

5 files changed

+47
-58
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
<!-- If your PR fixes an open issue, use `Closes #101` to link your PR with the issue. #101 stands for the issue number you are fixing -->
2-
3-
## 🛠️ Fixes Issue
4-
5-
<!-- Remove this section if not applicable -->
1+
### 🛠️ Fixes Issue <!-- Remove this section if not applicable -->
62

73
<!-- Example: Closes #31 -->
84

9-
## 👨‍💻 Changes proposed
5+
### 👨‍💻 Changes proposed
106

117
<!-- List all the proposed changes in your PR -->
128

13-
## ✔️ Check List (Check all the applicable boxes) <!-- Follow the below conventions to check the box -->
9+
### ✔️ Check List (Check all the applicable boxes) <!-- Follow the below conventions to check the box -->
1410

1511
<!-- Mark all the applicable boxes. To mark the box as done follow the following conventions -->
1612
<!--
@@ -21,9 +17,10 @@
2117
- [ ] My code follows the code style of this project.
2218
- [ ] This PR does not contain plagiarized content.
2319
- [ ] The title of my pull request is a short description of the requested changes.
20+
- [ ] 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).
2422

25-
## 📄 Note to reviewers
23+
### 📄 Note to reviewers <!-- Add notes to reviewers if applicable -->
2624

27-
<!-- Add notes to reviewers if applicable -->
2825

29-
## 📷 Screenshots
26+
### 📷 Screenshots <!-- Remove this section if not applicable -->

.github/workflows/releases.yml

+1-1
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

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
var rootCmd = &cobra.Command{
1414
Use: "candy [command]",
1515
Short: "Do all your tedious tasks with a single command",
16+
1617
Run: func(cmd *cobra.Command, args []string) {
1718
err := cmd.Help()
1819
checkNilErr(err)

cmd/update.go

+34
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 candy to the latest version",
14+
Long: `This command will help you to update candy 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/candy@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/version.go

+4-47
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,16 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7-
"github.com/tcnksm/go-latest"
87
)
98

10-
var (
11-
checkLatest bool
12-
)
13-
14-
const (
15-
CLI_VERSION = "1.7.0"
16-
OWNER = "Pradumnasaraf"
17-
REPO = "candy"
18-
)
9+
const CliVersion = "v1.8.0"
1910

2011
// versionCmd represents the version command
2112
var versionCmd = &cobra.Command{
2213
Use: "version",
23-
Short: "outputs the cli version",
14+
Short: "Know the installed version of candy",
15+
Long: `This command will help you to know the installed version of candy`,
2416
Run: func(cmd *cobra.Command, args []string) {
25-
26-
if checkLatest {
27-
checkForNewVersion()
28-
} else {
29-
fmt.Println(CLI_VERSION)
30-
}
31-
17+
fmt.Println("candy version:", CliVersion)
3218
},
3319
}
34-
35-
func checkForNewVersion() {
36-
37-
githubTag := &latest.GithubTag{
38-
Owner: OWNER,
39-
Repository: REPO,
40-
FixVersionStrFunc: latest.DeleteFrontV(),
41-
}
42-
43-
res, err := latest.Check(githubTag, CLI_VERSION)
44-
45-
if err != nil {
46-
fmt.Println("Unable to check for latest version. Check your internet connection")
47-
return
48-
}
49-
50-
if res.Outdated {
51-
fmt.Printf("The latest version of candy is %s.\nPlease update to the latest version by running go get -u github.com/Pradumnasaraf/candy@latest", res.Current)
52-
return
53-
}
54-
55-
fmt.Println("You are using the latest version of candy")
56-
57-
}
58-
59-
func init() {
60-
// Flags for the version command
61-
versionCmd.Flags().BoolVarP(&checkLatest, "latest", "l", false, "Check if the latest version is installed")
62-
}

0 commit comments

Comments
 (0)