Skip to content

Commit 1c44447

Browse files
committed
update: release details
1 parent d532797 commit 1c44447

File tree

8 files changed

+101
-126
lines changed

8 files changed

+101
-126
lines changed

api/cfg.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

api/release.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

cmd/release.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/GoFarsi/gvm/api"
65
"github.com/GoFarsi/gvm/errors"
6+
"github.com/GoFarsi/gvm/internal"
77
"log"
88

99
"github.com/spf13/cobra"
@@ -25,11 +25,16 @@ For example:
2525
}
2626

2727
if len(ver) != 0 {
28-
fmt.Println(api.GetDocVersion(ver))
28+
fmt.Println(internal.GetDocWithSpecificVersion(ver))
2929
return
3030
}
3131

32-
fmt.Println(api.GetFullDoc())
32+
doc, err := internal.GetFullDoc()
33+
if err != nil {
34+
log.Fatalln(err)
35+
}
36+
37+
fmt.Println(doc)
3338
},
3439
}
3540

errors/error.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ package errors
33
import "errors"
44

55
var (
6-
ERR_NETWORK_TIMEOUT = errors.New("cannot connect to network for get list of go versions")
7-
ERR_INVALID_VALUE = errors.New("invalid value of switch")
6+
ERR_NETWORK_TIMEOUT = errors.New("cannot connect to network for get list of go versions")
7+
ERR_INVALID_VALUE = errors.New("invalid value of switch")
8+
ERR_CANT_FIND_ACTIVE_MIRROR = errors.New("can't find active mirror on your network")
9+
ERR_SUDO_ACCESS = errors.New("for install,upgrade and downgrade please run gvm with sudo access")
10+
ERR_CANT_REMOVE_OLD_VERSION = errors.New("can't remove old version of go in /usr/local/go")
11+
ERR_CANT_SET_ENV = errors.New("can't set environment variable in /home/{user}/.profile file")
12+
ERR_UPGRADE_VERSION = errors.New("version request for upgrade should bigger than installed version of go")
13+
ERR_DOWNGRADE_VERSION = errors.New("version request for downgrade should smaller than installed version of go")
14+
ERR_READ_VERSION_CODE = errors.New("can't read version code")
815
)

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ module github.com/GoFarsi/gvm
22

33
go 1.19
44

5-
require github.com/spf13/cobra v1.6.1
5+
require (
6+
github.com/Code-Hex/pget v0.1.1
7+
github.com/spf13/cobra v1.6.1
8+
)
69

710
require (
8-
github.com/Code-Hex/pget v0.1.1 // indirect
911
github.com/Code-Hex/updater v0.0.0-20160712085121-c3f278672520 // indirect
1012
github.com/Songmu/prompter v0.5.1 // indirect
1113
github.com/VividCortex/ewma v1.2.0 // indirect
1214
github.com/antonholmquist/jason v1.0.1-0.20180605105355-426ade25b261 // indirect
1315
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
1416
github.com/cheggaaa/pb/v3 v3.1.0 // indirect
1517
github.com/fatih/color v1.13.0 // indirect
18+
github.com/hashicorp/go-version v1.6.0 // indirect
1619
github.com/inconshreveable/mousetrap v1.0.1 // indirect
1720
github.com/jessevdk/go-flags v1.5.0 // indirect
1821
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -22,7 +25,6 @@ require (
2225
github.com/pkg/errors v0.9.1 // indirect
2326
github.com/rivo/uniseg v0.4.2 // indirect
2427
github.com/spf13/pflag v1.0.5 // indirect
25-
golang.org/x/net v0.2.0 // indirect
2628
golang.org/x/sync v0.1.0 // indirect
2729
golang.org/x/sys v0.2.0 // indirect
2830
golang.org/x/term v0.2.0 // indirect

go.sum

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/o
1818
github.com/cheggaaa/pb/v3 v3.1.0 h1:3uouEsl32RL7gTiQsuaXD4Bzbfl5tGztXGUvXbs4O04=
1919
github.com/cheggaaa/pb/v3 v3.1.0/go.mod h1:YjrevcBqadFDaGQKRdmZxTY42pXEqda48Ea3lt0K/BE=
2020
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
21+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2122
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
23+
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
2224
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
2325
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
2426
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
2527
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
2628
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
2729
github.com/frankban/quicktest v1.11.1/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
30+
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
2831
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
2932
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
33+
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
34+
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
3035
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
3136
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3237
github.com/jessevdk/go-flags v0.0.0-20160903113131-4cc2832a6e6d/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -51,12 +56,16 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
5156
github.com/mcuadros/go-version v0.0.0-20141206211339-d52711f8d6be/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
5257
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 h1:YocNLcTBdEdvY3iDK6jfWXvEaM5OCKkjxPKoJRdB3Gg=
5358
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
59+
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
5460
github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
61+
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
5562
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
63+
github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI=
5664
github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
5765
github.com/pkg/errors v0.8.1-0.20161002052512-839d9e913e06/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5866
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
5967
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
68+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6069
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6170
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6271
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -68,13 +77,14 @@ github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUq
6877
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
6978
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
7079
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
80+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
7181
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
7282
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
83+
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
7384
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
85+
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
7486
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
7587
golang.org/x/net v0.0.0-20161013035702-8b4af36cd21a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
76-
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
77-
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
7888
golang.org/x/sync v0.0.0-20161004233620-1ae7c7b29e06/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7989
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
8090
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -95,4 +105,5 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
95105
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
96106
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
97107
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
108+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
98109
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/cfg.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package internal
2+
3+
import (
4+
"time"
5+
)
6+
7+
const (
8+
prefix = "go"
9+
refPrefix = "refs/tags/go"
10+
filePattern = "go%s.linux-%s.tar.gz"
11+
goInstallPath = "/usr/local/go"
12+
env = "export PATH=$PATH:/usr/local/go/bin"
13+
)
14+
15+
const (
16+
tagsAPI = "https://api.github.com/repos/golang/go/git/refs/tags"
17+
releaseDoc = "https://go.dev/doc/go"
18+
)
19+
20+
const (
21+
_defaultMirrorTimeout = 15 * time.Second
22+
)
23+
24+
const (
25+
INSTALL = "install"
26+
UPGRADE = "upgrade"
27+
DOWNGRADE = "downgrade"
28+
)
29+
30+
var mirrors = map[string]string{
31+
"default": "https://go.dev/dl/",
32+
"gomirrors": "https://gomirrors.org/dl/go/",
33+
}
34+
35+
var (
36+
warningInstalledGo = "Go installed with version %s in path %s, are you sure continue %s operate?"
37+
warningSudoAccess = "For %s operation you need have 'sudo' access, are you sure have 'sudo' access?"
38+
)

internal/release.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package internal
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
func GetDocWithSpecificVersion(ver string) string {
9+
return releaseDoc + ver
10+
}
11+
12+
func GetFullDoc() (string, error) {
13+
list, err := NewList()
14+
if err != nil {
15+
return "", err
16+
}
17+
18+
vers := list.GetVersions()
19+
20+
var b strings.Builder
21+
for _, v := range vers {
22+
if len(v) > 4 {
23+
continue
24+
}
25+
fmt.Fprintf(&b, "go%s\t\t%s\n", v, releaseDoc+v)
26+
}
27+
return b.String(), nil
28+
}

0 commit comments

Comments
 (0)