cli

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChkCmd = &cobra.Command{
	Use:               "chk",
	Aliases:           []string{"check"},
	Short:             "Run linters that only check code",
	Long:              `Check all code standards for coding conventions`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		err := crieRun.Run(runner.LintTypeChk)

		if err != nil {
			log.Fatal(errchain.From(err).Link("crie check"))
		}
	},
}

ChkCmd Run all code checking commands

View Source
var ConfCmd = &cobra.Command{
	Use:               "conf",
	Aliases:           []string{"config", "cnf"},
	Short:             "Print configuration settings",
	Long:              "Print what crie has parsed from flags, env, the project file, and then defaults",
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	RunE: func(_ *cobra.Command, _ []string) error {
		var projectConfig project.Config
		err := viper.Unmarshal(&projectConfig)
		if err != nil {
			return err
		}
		marshal, err := yaml.Marshal(projectConfig)
		if err != nil {
			return err
		}

		fmt.Println(string(marshal))
		return nil
	},
}

ConfCmd is used to show configuration settings after flags, env, configs are parsed

View Source
var FmtCmd = &cobra.Command{
	Use:               "fmt",
	Short:             "Run formatters",
	Long:              `Run all formatters in the list`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		err := crieRun.Run(runner.LintTypeFmt)

		if err != nil {
			log.Fatal(errchain.From(err).Link("crie format"))
		}
	},
}

FmtCmd Format code command

View Source
var InitCmd = &cobra.Command{
	Use:               "init",
	Short:             "Create optional config files",
	Long:              `Create an optional project file and an extra optional language override file`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	RunE: func(_ *cobra.Command, _ []string) error {

		err := language.NewLanguageConfigFile(viper.GetString("Language.Conf"))
		if err != nil {
			return err
		}
		fmt.Printf("new language file created: %s\nused to overide crie internal language settings (optional and can be deleted)\n", viper.GetString("Language.Conf"))

		fmt.Println()

		var projectConfig project.Config
		err = viper.Unmarshal(&projectConfig)
		if err != nil {
			return err
		}
		err = projectConfig.NewProjectConfigFile(viper.GetString("Project.Conf"))
		if err != nil {
			return err
		}
		fmt.Printf("new project file created: %s\nthis will be treated as your project defaults (overiden by flags and env)\n", viper.GetString("Project.Conf"))
		return nil
	},
}

InitCmd command will create a project project file for crieRun

View Source
var LntCmd = &cobra.Command{
	Use:               "lnt",
	Aliases:           []string{"lint", "all"},
	Short:             "Runs both fmt and then chk",
	Long:              `Runs both format and then check`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		stages := []runner.LintType{runner.LintTypeFmt, runner.LintTypeChk}
		var failedStages []string

		for _, lintType := range stages {
			if err := stage(lintType); err != nil {
				if crieRun.Options.Continue {
					failedStages = append(failedStages, lintType.String())
				} else {
					log.Fatal(err)
				}
			}
		}

		if len(failedStages) > 0 {
			log.Fatal(fmt.Errorf("crie stages failed: %s", strings.Join(failedStages, ", ")))
		}
	},
}

LntCmd Runs all commands

View Source
var LsCmd = &cobra.Command{
	Use:               "ls",
	Aliases:           []string{"list"},
	Short:             "Show languages",
	Long:              `Show all languages available and the commands run when used`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		err := crieRun.Languages.Show(os.Stdout)
		if err != nil {
			log.Fatal(errchain.From(err).Link("crie list failed"))
		}
	},
}

LsCmd Show support languages command

View Source
var NonCmd = &cobra.Command{
	Use:     "non",
	Aliases: []string{"not-linted"},
	Short:   "Show what isn't supported for this project",
	Long: `Show what isn't supported for this project

Find the file extensions that dont have an associated regex match within crie`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		err := crieRun.NoStandards()
		if err != nil {
			log.Fatal(errchain.From(err).Link("finding unassociated files"))
		}
	},
}

NonCmd Show every type of file that just passes through

View Source
var RootCmd = &cobra.Command{
	Use:   "crie",
	Short: "crie is a formatter and linter for many languages.",
	Example: `
check all files changes since the target branch 
	$ crie chk --git-diff --git-target=origin/main

format all python files
	$ crie fmt --only python
`,
	Long: `
	crie brings together a vast collection of formatters and linters
	to create a handy tool that can sanity check any codebase.`,
	PersistentPreRunE: func(_ *cobra.Command, _ []string) error {

		viper.SetConfigFile(projectConfigPath)
		viper.SetConfigType("yml")
		viper.SetEnvPrefix("CRIE")
		viper.AutomaticEnv()
		viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

		_ = viper.ReadInConfig()
		err := viper.Unmarshal(&projectConfig)
		if err != nil {
			return err
		}

		setLogging()

		if projectConfig.Lint.GitTarget != "" {
			projectConfig.Lint.GitDiff = true
		}

		return nil
	},
}

RootCmd is the root Cobra command for the crie CLI. It wires configuration, global flags, and subcommands together.

View Source
var SchemaCmd = &cobra.Command{
	Use:     "schema",
	Aliases: []string{"sch"},
	Short:   "Print JSON schemas for config files",
	Long:    `Print JSON schemas for config files`,
}

SchemaCmd is used to hold jsonschema generator commands

View Source
var SchemaLangCmd = &cobra.Command{
	Use:               "lang",
	Aliases:           []string{"language", "lng"},
	Short:             "Print the schema for language's configurations",
	Long:              `Print json schema for cries configuration format used override language project`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		schema := language.Schema()
		jsonBytes, err := json.MarshalIndent(schema, "", "  ")
		if err != nil {
			return
		}
		fmt.Println(string(jsonBytes))
	},
}

SchemaLangCmd is the jsonschema generator for the crie languages configuration

View Source
var SchemaProjectCmd = &cobra.Command{
	Use:               "proj",
	Aliases:           []string{"project", "prj"},
	Short:             "Print the schema for language's configurations",
	Long:              `Print json schema for cries configuration format used override language project`,
	Args:              cobra.NoArgs,
	ValidArgsFunction: cobra.FixedCompletions(nil, cobra.ShellCompDirectiveNoFileComp),
	Run: func(_ *cobra.Command, _ []string) {
		schema := project.Schema()
		jsonBytes, err := json.MarshalIndent(schema, "", "  ")
		if err != nil {
			return
		}
		fmt.Println(string(jsonBytes))
	},
}

SchemaProjectCmd is the jsonschema generator for the crie project configuration

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL