Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mostly global config object thing #4

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions cli-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,27 +205,9 @@ func fetchTools(runtime *config.Runtime, runtimesDirectory string, toolsDirector
}
}

func main() {
homePath, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

codacyDirectory := filepath.Join(homePath, ".cache", "codacy")
runtimesDirectory := filepath.Join(codacyDirectory, "runtimes")
toolsDirectory := filepath.Join(codacyDirectory, "tools")
fmt.Println("creating: " + codacyDirectory)
if os.MkdirAll(codacyDirectory, 0777) != nil {
log.Fatal(err)
}
fmt.Println("creating: " + runtimesDirectory)
if os.MkdirAll(runtimesDirectory, 0777) != nil {
log.Fatal(err)
}
fmt.Println("creating: " + toolsDirectory)
if os.MkdirAll(toolsDirectory, 0777) != nil {
log.Fatal(err)
}
func main() {
config.Init()

// TODO can use a variable to stored the "local" codacy dir
runtimes, configErr := config.ReadConfigFile(filepath.Join(".codacy", "codacy.yaml"))
Expand All @@ -234,9 +216,9 @@ func main() {
}

// install runtimes
fetchRuntimes(runtimes, runtimesDirectory)
fetchRuntimes(runtimes, config.Config.RuntimesDirectory())
for _, r := range runtimes {
fetchTools(r, runtimesDirectory, toolsDirectory)
fetchTools(r, config.Config.RuntimesDirectory(), config.Config.ToolsDirectory())
}

cmd.Execute()
Expand Down
18 changes: 18 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(analyzeCmd)
}

var analyzeCmd = &cobra.Command{
Use: "analyze",
Short: "Runs all linters.",
Long: "Runs all tools for all runtimes.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hello from 'analyze'")
},
}
61 changes: 61 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package config

import (
"log"
"os"
"path/filepath"
)

type configType struct {
homePath string
codacyDirectory string
runtimesDirectory string
toolsDirectory string
}

var Config = configType{}

func (c *configType) HomePath() string {
return c.homePath
}

func (c *configType) CodacyDirectory() string {
return c.codacyDirectory
}

func (c *configType) RuntimesDirectory() string {
return c.runtimesDirectory
}

func (c *configType) ToolsDirectory() string {
return c.toolsDirectory
}

func (c *configType) initCodacyDirs() {
c.codacyDirectory = filepath.Join(c.homePath, ".cache", "codacy")
c.runtimesDirectory = filepath.Join(c.codacyDirectory, "runtimes")
c.toolsDirectory = filepath.Join(c.codacyDirectory, "tools")

err := os.MkdirAll(c.codacyDirectory, 0777)
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(c.runtimesDirectory, 0777)
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(c.toolsDirectory, 0777)
if err != nil {
log.Fatal(err)
}
}

func Init() {
homePath, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
Config.homePath = homePath

Config.initCodacyDirs()
}
Loading