Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Evsyukov Denis <denis.evsyukov@flant.com>
  • Loading branch information
juev committed Sep 9, 2024
1 parent 7bb8d42 commit 7f0060d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
42 changes: 35 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/deckhouse/d8-lint/pkg/config"
)

type rootCommand struct {
viper *viper.Viper
cmd *cobra.Command

cfg *config.Config
//
// exitCode int
}

var (
cfgFile string
version = "HEAD"

printVersion bool
)

func newRunCommand() *rootCommand {
c := &rootCommand{
viper: viper.New(),
cfg: config.NewDefault(),
}

// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
runCmd := &cobra.Command{
Use: "d8-lint",
Short: "d8-lint is a smart linters runner.",
Long: `Smart, fast linters runner.`,
Expand All @@ -27,21 +45,31 @@ var (
fmt.Println("lint called")
},
}
)

fs := runCmd.Flags()
fs.StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.d8lint.yaml)")
fs.BoolVarP(&printVersion, "version", "v", false, "print version")

c.cmd = runCmd

return c
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.d8lint.yaml)")
rootCmd.Flags().BoolVarP(&printVersion, "version", "v", false, "print version")

err := rootCmd.Execute()
err := newRunCommand().Execute()
if err != nil {
os.Exit(1)
}
}

func (c *rootCommand) Execute() error {
cobra.OnInitialize(initConfig)

return c.cmd.Execute()
}

func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ type Config struct {
LintersSettings LintersSettings `mapstructure:"linters-settings"`
Linters Linters `mapstructure:"linters"`
}

func NewDefault() *Config {
return &Config{
LintersSettings: defaultLintersSettings,
}
}
2 changes: 1 addition & 1 deletion pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
)

// var defaultLintersSettings = LintersSettings{}
var defaultLintersSettings = LintersSettings{}

type LintersSettings struct {
Custom map[string]CustomLinterSettings
Expand Down

0 comments on commit 7f0060d

Please sign in to comment.