Skip to content

Commit

Permalink
fixes w/ satisfy command
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jul 25, 2022
1 parent db98b4e commit b5a81b4
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.1
1.17
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<p align="center">
<img alt="Goenv Logo" src="/static/logo1.png?v=1.4.8" width="200" />
<img alt="Goenv Logo" src="/static/logo1.png?v=1.5.0" width="200" />
<h3 align="center">Goenv</h3>
<p align="center">Manage Your Applications Go Environment</p>
<p align="center">
<a href="https://github.com/spacewalkio/Goenv/actions/workflows/build.yml">
<img src="https://github.com/spacewalkio/Goenv/actions/workflows/build.yml/badge.svg">
</a>
<a href="https://github.com/spacewalkio/Goenv/releases">
<img src="https://img.shields.io/badge/Version-v1.4.8-red.svg">
<img src="https://img.shields.io/badge/Version-v1.5.0-red.svg">
</a>
<a href="https://goreportcard.com/report/github.com/spacewalkio/Goenv">
<img src="https://goreportcard.com/badge/github.com/spacewalkio/Goenv?v=1.4.8">
<img src="https://goreportcard.com/badge/github.com/spacewalkio/Goenv?v=1.5.0">
</a>
<a href="https://godoc.org/github.com/spacewalkio/goenv">
<img src="https://godoc.org/github.com/spacewalkio/goenv?status.svg">
Expand Down
131 changes: 131 additions & 0 deletions cmd/satisfy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright 2022 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.

package cmd

import (
"fmt"
"os"

"github.com/spacewalkio/goenv/core/module"

"github.com/spf13/cobra"
)

var satisfyCmd = &cobra.Command{
Use: "satisfy",
Short: "Satisfy the current directry go version.",
Run: func(cmd *cobra.Command, args []string) {

golang := module.NewGolangEnvironment(HOME)

cdir, err := os.Getwd()

if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

version, err := golang.GetLocalVersion(cdir)

if err == nil {
// Validate version
if !golang.ValidateVersion(version) {
fmt.Printf("Error! Invalid version detected %s\n", version)
os.Exit(1)
}

isInstalled, err := golang.ValidateInstalledVersion(version)

if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

if isInstalled {
fmt.Printf("Go Version %s is already installed\n", version)
return
}

// Show a loading spinner
spinner := module.NewCharmSpinner(fmt.Sprintf(
"Getting Go v%s Environment Ready",
version,
))

go func() {
// Download and install the go version
err = golang.Install(version)

if err != nil {
fmt.Println(err.Error())
}

spinner.Quit()
}()

// Start the spinner
if err := spinner.Start(); err != nil {
fmt.Printf("Error showing loading bar: %s\n", err.Error())
os.Exit(1)
}

return
}

version, err = golang.GetGlobalVersion()

if err == nil {
// Validate version
if !golang.ValidateVersion(version) {
fmt.Printf("Error! Invalid version detected %s\n", version)
os.Exit(1)
}

isInstalled, err := golang.ValidateInstalledVersion(version)

if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

if isInstalled {
fmt.Printf("Go Version %s is already installed\n", version)
return
}

// Show a loading spinner
spinner := module.NewCharmSpinner(fmt.Sprintf(
"Getting Go v%s Environment Ready",
version,
))

go func() {
// Download and install the go version
err = golang.Install(version)

if err != nil {
fmt.Println(err.Error())
}

spinner.Quit()
}()

// Start the spinner
if err := spinner.Start(); err != nil {
fmt.Printf("Error showing loading bar: %s\n", err.Error())
os.Exit(1)
}

return
}

fmt.Println(err.Error())
os.Exit(1)
},
}

func init() {
rootCmd.AddCommand(satisfyCmd)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spacewalkio/goenv

go 1.18
go 1.17

require (
github.com/charmbracelet/bubbles v0.13.0
Expand Down

0 comments on commit b5a81b4

Please sign in to comment.