-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from kumparan/feature/gocek
feature: add gocek
- Loading branch information
Showing
12 changed files
with
397 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"gocek": { | ||
"project_directories": [], | ||
"output_save_folder": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// FerConfigPath :nodoc: | ||
func FerConfigPath() string { | ||
return filepath.Join(os.Getenv("HOME"), ".ferconfig.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"sync" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var cfg FerConfig | ||
var once sync.Once | ||
|
||
// GocekConfig :nodoc: | ||
type GocekConfig struct { | ||
ProjectDirs []string `json:"project_directories"` | ||
SaveOutputDir string `json:"output_save_folder"` | ||
} | ||
|
||
// FerConfig :nodoc: | ||
type FerConfig struct { | ||
Gocek GocekConfig `json:"gocek"` | ||
} | ||
|
||
func init() { | ||
once.Do(func() { | ||
loadCfg() | ||
}) | ||
} | ||
|
||
func loadCfg() { | ||
cfgPath := FerConfigPath() | ||
_, err := os.Stat(cfgPath) | ||
switch { | ||
case os.IsNotExist(err): | ||
f, err := os.Create(cfgPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
cfg.Gocek.ProjectDirs = make([]string, 0) | ||
bt, _ := json.MarshalIndent(cfg, "", " ") | ||
_, err = f.Write([]byte(bt)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
case err == nil: | ||
b, err := ioutil.ReadFile(FerConfigPath()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = json.Unmarshal(b, &cfg) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
default: | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// GetFerConfig :nodoc: | ||
func GetFerConfig() FerConfig { | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package config | ||
|
||
// Version define version of fer | ||
const Version = "v1.5.4" | ||
const Version = "v1.6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package console | ||
|
||
import ( | ||
"github.com/kumparan/fer/config" | ||
"github.com/kumparan/fer/gocek" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
gocekCmd.AddCommand(gocekAllCmd) | ||
rootCmd.AddCommand(gocekCmd) | ||
} | ||
|
||
var gocekCmd = &cobra.Command{ | ||
Use: "gocek", | ||
Short: "gocek check a module update info", | ||
Long: `default check current working directory`, | ||
Run: gocekCWD, | ||
} | ||
|
||
var gocekAllCmd = &cobra.Command{ | ||
Use: "all", | ||
Short: "check all module update info", | ||
Run: gocekAll, | ||
} | ||
|
||
func gocekAll(cmd *cobra.Command, args []string) { | ||
cfg := config.GetFerConfig() | ||
checker := gocek.ModuleChecker{ | ||
RootDir: cfg.Gocek.SaveOutputDir, | ||
} | ||
|
||
checker.Checks(cfg.Gocek.ProjectDirs) | ||
} | ||
|
||
func gocekCWD(cmd *cobra.Command, args []string) { | ||
checker := gocek.ModuleChecker{} | ||
checker.CheckCWD() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.