Skip to content

Commit

Permalink
feature: update gocek checker result path
Browse files Browse the repository at this point in the history
  • Loading branch information
fahmi.irfan committed Sep 9, 2020
1 parent 3c20661 commit d27ebc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
5 changes: 3 additions & 2 deletions console/gocek.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ var gocekAllCmd = &cobra.Command{
func gocekAll(cmd *cobra.Command, args []string) {
cfg := config.GetFerConfig()
checker := gocek.ModuleChecker{
RootDir: cfg.Gocek.SaveOutputDir,
RootDir: cfg.Gocek.SaveOutputDir,
ServicesDirs: cfg.Gocek.ProjectDirs,
}

checker.Checks(cfg.Gocek.ProjectDirs)
checker.Checks()
}

func gocekCWD(cmd *cobra.Command, args []string) {
Expand Down
41 changes: 24 additions & 17 deletions gocek/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (

const (
_defaultMaxQueueSize = int(10)
timeLayout = "2006-01-02"
)

// ModuleChecker :nodoc:
type ModuleChecker struct {
RootDir string
RootDir string
ServicesDirs []string
}

// CheckCWD call CheckCWD() and print into stdout
// CheckCWD call checkCWD() and print into stdout
func (mc *ModuleChecker) CheckCWD() {
modlist, err := CheckCWD()
modlist, err := checkCWD()
if err != nil {
log.Fatal(err)
}
Expand All @@ -40,16 +42,24 @@ func (mc *ModuleChecker) CheckCWD() {
}

// Checks check module projects and save the json file
func (mc *ModuleChecker) Checks(dirs []string) {
for _, dir := range dirs {
func (mc *ModuleChecker) Checks() {
now := time.Now()
folder := now.Format(timeLayout)
savePath := path.Join(mc.RootDir, folder)
err := os.MkdirAll(savePath, 0755)
if err != nil {
log.Fatal(err)
}

for _, dir := range mc.ServicesDirs {
os.Chdir(dir)
modules, err := CheckCWD()
modules, err := checkCWD()
if err != nil {
continue
}

sdir := strings.Split(dir, "/")
err = mc.save(sdir[len(sdir)-1], modules)
err = mc.save(savePath, sdir[len(sdir)-1], modules)
if err != nil {
log.Error(err)
return
Expand All @@ -59,13 +69,9 @@ func (mc *ModuleChecker) Checks(dirs []string) {
}

// save modules as json
func (mc *ModuleChecker) save(modName string, modules []*SimpleModule) error {
now := time.Now()
layout := "2006-01-02"
fileName := fmt.Sprintf("%s.%s.json", modName, now.Format(layout))
dst := path.Join(mc.RootDir, fileName)

f, err := os.Create(dst)
func (mc *ModuleChecker) save(savePath, modName string, modules []*SimpleModule) error {
fileName := fmt.Sprintf("%s.json", modName)
f, err := os.Create(path.Join(savePath, fileName))
if err != nil {
log.Error(err)
return err
Expand All @@ -83,8 +89,8 @@ func (mc *ModuleChecker) save(modName string, modules []*SimpleModule) error {
return err
}

// CheckCWD check current working directory
func CheckCWD() (modules []*SimpleModule, err error) {
// checkCWD check current working directory
func checkCWD() (modules []*SimpleModule, err error) {
modList, err := findDirectModList()
if err != nil {
log.Error(err)
Expand Down Expand Up @@ -118,7 +124,7 @@ func findAllModuleUpdate(mods []string) (modules []*SimpleModule, err error) {

mod, err := findModuleUpdate(m)
if err != nil {
log.Error(err)
log.Error("findModuleUpdate: ", err)
return
}

Expand Down Expand Up @@ -183,6 +189,7 @@ func findModList() ([]string, error) {
func findDirectModList() ([]string, error) {
out, err := exec.Command("go", "list", "-m", "-f", `{{ .Path }} | {{ .Indirect }}`, "all").Output()
if err != nil {
log.Error("findDirectModList: ", err)
return nil, err
}
splitted := strings.Split(string(out), "\n")
Expand Down

0 comments on commit d27ebc3

Please sign in to comment.