fix remove cmd
This commit is contained in:
parent
c5c14ef29a
commit
341fe743a1
92
cmd/cmd.go
92
cmd/cmd.go
|
@ -13,6 +13,7 @@ import (
|
|||
"gitea.antoine-langlois.net/datahearth/doggo-fetcher/pkg"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -284,7 +285,6 @@ func initFunc(ctx *cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// todo:
|
||||
func uninstall(ctx *cli.Context) error {
|
||||
return os.RemoveAll(filepath.Join(dgfFolder, "go"))
|
||||
}
|
||||
|
@ -321,70 +321,54 @@ func remove(ctx *cli.Context) error {
|
|||
Logger.Level = logrus.DebugLevel
|
||||
}
|
||||
|
||||
if !ctx.Bool("all") {
|
||||
if ctx.NArg() == 0 {
|
||||
return errors.New("a release is required")
|
||||
}
|
||||
release := ctx.Args().First()
|
||||
if !re.Match([]byte(release)) {
|
||||
return errors.New("release doesn't match \"\\d*\\.?\\d*\\.?\\d(rc|beta)?\\d*?\" format")
|
||||
}
|
||||
hash, err := pkg.NewHash(dgfFolder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(filepath.Join(dgfFolder, fmt.Sprintf("go%s", release))); err != nil {
|
||||
return fmt.Errorf("could not remove release %s: %s", release, err)
|
||||
}
|
||||
|
||||
if err := hash.RemoveHash(fmt.Sprintf("%s/go%s", dgfFolder, release)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(runtime.Version(), ctx.Args().First()) {
|
||||
Logger.Infoln("Removing installed version...")
|
||||
if err := os.RemoveAll(filepath.Join(dgfFolder, "go")); err != nil {
|
||||
return fmt.Errorf("could not remove installed release %s: %s", release, err)
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Info("Release removed")
|
||||
return nil
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dgfFolder)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read local folder: %s", err)
|
||||
}
|
||||
|
||||
hash, err := pkg.NewHash(dgfFolder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, f := range entries {
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
releasesPath := []string{}
|
||||
if ctx.Bool("all") {
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() || !strings.Contains(e.Name(), "go") || e.Name() == "go" {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(f.Name(), "go") && f.Name() != "go" {
|
||||
folderPath := filepath.Join(dgfFolder, f.Name())
|
||||
if err := os.RemoveAll(folderPath); err != nil {
|
||||
return fmt.Errorf("could not remove %s: %s", folderPath, err)
|
||||
}
|
||||
if err := hash.RemoveHash(folderPath); err != nil {
|
||||
return err
|
||||
}
|
||||
releasesPath = append(releasesPath, filepath.Join(dgfFolder, e.Name()))
|
||||
}
|
||||
} else {
|
||||
found := slices.ContainsFunc(entries, func(e os.DirEntry) bool {
|
||||
return e.IsDir() && e.Name() == fmt.Sprintf("go%s", ctx.Args().First())
|
||||
})
|
||||
if !found {
|
||||
return fmt.Errorf("release %s not found", ctx.Args().First())
|
||||
}
|
||||
releasesPath = append(releasesPath, filepath.Join(dgfFolder, fmt.Sprintf("go%s", ctx.Args().First())))
|
||||
}
|
||||
|
||||
hash, err := pkg.NewHash(hashFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, e := range releasesPath {
|
||||
Logger.Infof("Removing %s...", filepath.Base(e))
|
||||
if err := os.RemoveAll(e); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hash.RemoveHash(e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Infoln("Removing installed version...")
|
||||
if err := os.RemoveAll(filepath.Join(dgfFolder, "go")); err != nil {
|
||||
return fmt.Errorf("could not remove installed release: %s", err)
|
||||
if strings.Contains(runtime.Version(), ctx.Args().First()) {
|
||||
Logger.Infoln("Removing installed version...")
|
||||
if err := os.RemoveAll(filepath.Join(dgfFolder, "go")); err != nil {
|
||||
return fmt.Errorf("could not remove installed release: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Info("All releases removed")
|
||||
Logger.Infoln("All done!")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
7
go.mod
7
go.mod
|
@ -1,11 +1,11 @@
|
|||
module gitea.antoine-langlois.net/datahearth/doggo-fetcher
|
||||
|
||||
go 1.18
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/briandowns/spinner v1.18.1
|
||||
github.com/google/go-github/v45 v45.1.0
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/urfave/cli/v2 v2.8.1
|
||||
)
|
||||
|
||||
|
@ -18,5 +18,6 @@ require (
|
|||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
)
|
||||
|
|
10
go.sum
10
go.sum
|
@ -9,6 +9,7 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
|||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v45 v45.1.0 h1:SbUjHMRiCe9cHfu6Me4idWxLQEV8ZW9DLPz69zopyWo=
|
||||
github.com/google/go-github/v45 v45.1.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
|
@ -21,8 +22,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
@ -32,9 +33,12 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT
|
|||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
|
|
Reference in New Issue