Skip to content

Commit

Permalink
add update command
Browse files Browse the repository at this point in the history
  • Loading branch information
AshutoshPatole committed Aug 13, 2024
1 parent 28441cd commit 0a14674
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 22 deletions.
41 changes: 37 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ before:
hooks:
- go mod tidy
- go generate ./...
git:
ignore_tags:
- "{{ if not .IsNightly }}nightly{{ end }}"

metadata:
mod_timestamp: "{{ .CommitTimestamp }}"
Expand All @@ -28,7 +25,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=Ashutosh -X main.treeState={{ .IsGitDirty }}
- -s -w -X github.com/AshutoshPatole/ssm-v2/cmd.version={{.Version}} -X github.com/AshutoshPatole/ssm-v2/cmd.commit={{.Commit}} -X github.com/AshutoshPatole/ssm-v2/cmd.date={{ .CommitDate }} -X github.com/AshutoshPatole/ssm-v2/cmd.builtBy={{ .CommitTimestamp }} -X github.com/AshutoshPatole/ssm-v2/cmd.treeState={{ .IsGitDirty }}


archives:
Expand All @@ -50,3 +47,39 @@ changelog:
exclude:
- "^docs:"
- "^test:"


# .goreleaser.yaml
nfpms:
-
id: ssmv2
package_name: ssm

file_name_template: "{{ .ConventionalFileName }}"

vendor: AshutoshPatole

# Your app's homepage.
#
# Default: inferred from global metadata.
homepage: https://github.com/AshutoshPatole/ssm-v2

# Your app's maintainer (probably you).
#
# Default: inferred from global metadata.
maintainer: AshutoshPatole <apatole479@gmail.com>

# Your app's description.
#
# Default: inferred from global metadata.
description: |-
A simple SSH manager utility
# Formats to be generated.
formats:
- deb
- rpm




2 changes: 1 addition & 1 deletion cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cmd

import (
"errors"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"ssm-v2/internal/ssh"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package cmd
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/TwiN/go-color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"os"
"ssm-v2/internal/ssh"
"ssm-v2/internal/store"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package cmd
import (
"bufio"
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"ssm-v2/internal/store"
"strings"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package cmd

import (
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"os"
"ssm-v2/internal/ssh"
"ssm-v2/internal/store"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cmd
import (
"cloud.google.com/go/firestore"
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/sirupsen/logrus"
"os"
"path"
"ssm-v2/internal/ssh"
"ssm-v2/internal/store"

"context"
"github.com/spf13/cobra"
Expand Down
4 changes: 2 additions & 2 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"cloud.google.com/go/firestore"
"context"
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"log"
"os"
"ssm-v2/internal/ssh"
"ssm-v2/internal/store"
)

// pushCmd represents the push command
Expand Down
4 changes: 2 additions & 2 deletions cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package cmd

import (
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"ssm-v2/internal/ssh"
"ssm-v2/internal/store"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/reverseCopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd

import (
"fmt"
ssh2 "github.com/AshutoshPatole/ssm-v2/internal/ssh"
"github.com/TwiN/go-color"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand All @@ -12,7 +13,6 @@ import (
"log"
"os"
"path/filepath"
ssh2 "ssm-v2/internal/ssh"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
package cmd

import (
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"os"
"ssm-v2/internal/store"
)

// templateCmd represents the template command
Expand Down
85 changes: 85 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package cmd

import (
"encoding/json"
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/spf13/cobra"
"net/http"
)

// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update",
Short: "checks for latest update",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
currentVersion, err := semver.NewVersion(version)
if err != nil {
fmt.Printf("Error parsing current version: %s\n", err)
return
}

fmt.Printf("Current version: %s\n", currentVersion)

latestRelease, err := getLatestRelease()
if err != nil {
fmt.Printf("Error fetching latest release: %s\n", err)
return
}

latestVersion, err := semver.NewVersion(latestRelease.TagName)
if err != nil {
fmt.Printf("Error parsing latest version: %s\n", err)
return
}
if latestVersion.GreaterThan(currentVersion) {
fmt.Printf("New version available: %s\n", latestVersion)
} else {
fmt.Println("You're already on the latest version.")
}
},
}

func init() {
rootCmd.AddCommand(updateCmd)
}

type GitHubRelease struct {
TagName string `json:"tag_name"`
Assets []struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
} `json:"assets"`
}

var (
owner = "AshutoshPatole"
repo = "ssm-v2"
)

func getLatestRelease() (*GitHubRelease, error) {
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", owner, repo)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var release GitHubRelease
//body, err := io.ReadAll(resp.Body)
//if err != nil {
// fmt.Println("Error reading response body:", err)
// os.Exit(1)
//}
//
//// Print the response body
//fmt.Println(string(body))
err = json.NewDecoder(resp.Body).Decode(&release)
if err != nil {
return nil, err
}

return &release, nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module ssm-v2
module github.com/AshutoshPatole/ssm-v2

go 1.22

require (
cloud.google.com/go/firestore v1.16.0
firebase.google.com/go v3.13.0+incompatible
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Masterminds/semver/v3 v3.2.1
github.com/TwiN/go-color v1.4.1
github.com/caarlos0/go-version v0.1.1
github.com/charmbracelet/bubbletea v0.26.6
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/TwiN/go-color v1.4.1 h1:mqG0P/KBgHKVqmtL5ye7K0/Gr4l6hTksPgTgMk3mUzc=
Expand Down
5 changes: 3 additions & 2 deletions internal/ssh/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package ssh

import (
"fmt"
"github.com/AshutoshPatole/ssm-v2/internal/configuration"
"github.com/AshutoshPatole/ssm-v2/internal/store"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"ssm-v2/internal/configuration"
"ssm-v2/internal/store"

"time"
)

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "ssm-v2/cmd"
import "github.com/AshutoshPatole/ssm-v2/cmd"

func main() {
cmd.Execute()
Expand Down

0 comments on commit 0a14674

Please sign in to comment.