Skip to content

Commit

Permalink
chore: change loader
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingandyyy committed Apr 17, 2022
1 parent 9797cf5 commit 94fde5f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.0.4
Binary file modified bin/gofuzzyclone
Binary file not shown.
33 changes: 15 additions & 18 deletions gofuzzyclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"golang.org/x/oauth2"
)

var gofuzzycloneConfigFilePath string = os.ExpandEnv("$HOME/.gofuzzyclone.json")
var configFilePath string = os.ExpandEnv("$HOME/.gofuzzyclone.json")

func check(e error) {
if e != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func printf(color string, message string) {
fmt.Printf("%s%s%s", string(color_palettes[color]), message, color_palettes["reset"])
}

type gofuzzycloneConfig struct {
type config struct {
Ghtoken string `json:"github_token"`
}

Expand All @@ -79,22 +79,22 @@ func renewGhToken() {
println("green", "Token is valid")

var jsonBlob = []byte(`{"github_token": "` + ghToken + `"}`)
gofuzzycloneConfig := gofuzzycloneConfig{}
err := json.Unmarshal(jsonBlob, &gofuzzycloneConfig)
cf := config{}
err := json.Unmarshal(jsonBlob, &cf)
if err != nil {
panic(err)
}
if _, err := os.Stat(gofuzzycloneConfigFilePath); err == nil {
if _, err := os.Stat(configFilePath); err == nil {
hasConfigFile = true
}
if os.Getenv("CI") != "true" {
gofuzzycloneConfigJson, _ := json.Marshal(gofuzzycloneConfig)
cfJson, _ := json.Marshal(cf)
if !hasConfigFile {
// create one
f, err := os.Create(gofuzzycloneConfigFilePath)
f, err := os.Create(configFilePath)
check(err)
defer f.Close()
err = ioutil.WriteFile(gofuzzycloneConfigFilePath, gofuzzycloneConfigJson, 0644)
err = ioutil.WriteFile(configFilePath, cfJson, 0644)
check(err)
}
}
Expand Down Expand Up @@ -203,16 +203,13 @@ func main() {
os.Exit(0)
}
ghToken := os.Getenv("GITHUB_TOKEN")
if _, err := os.Stat(gofuzzycloneConfigFilePath); err == nil {
if _, err := os.Stat(configFilePath); err == nil {
// config file does exist
config, _ := os.ReadFile(gofuzzycloneConfigFilePath)
var gofuzzycloneConfig gofuzzycloneConfig
err := json.Unmarshal(config, &gofuzzycloneConfig)
if err != nil {
panic(err)
}
if gofuzzycloneConfig.Ghtoken != "" {
ghToken = gofuzzycloneConfig.Ghtoken
existingConfig, _ := os.ReadFile(configFilePath)
var cf config
json.Unmarshal(existingConfig, &cf)
if cf.Ghtoken != "" {
ghToken = cf.Ghtoken
}
validateGhToken(ghToken)
}
Expand All @@ -230,7 +227,7 @@ func main() {
fmt.Scanf("%s", owner)
}

s := spinner.New(spinner.CharSets[39], 200*time.Millisecond) // Build our new spinner
s := spinner.New(spinner.CharSets[4], 200*time.Millisecond) // Build our new spinner
s.Prefix = fmt.Sprintf("Searching %q ", *search)
s.Start() // Start the spinner

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

export version=0.0.3
export version=0.0.4
export author=amazingandyyy
export package_name=gofuzzyclone

Expand Down

0 comments on commit 94fde5f

Please sign in to comment.