Skip to content

Commit

Permalink
feat: add support for VALE_STYLES_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Feb 16, 2024
1 parent a76bcc4 commit 2139c41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/vale/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var commandInfo = map[string]string{
"ls-config": "Print the current configuration to stdout.",
"ls-metrics": "Print the given file's internal metrics to stdout.",
"ls-dirs": "Print the default configuration directories to stdout.",
"ls-vars": "Print the supported enviroment variables to stdout.",
"sync": "Download and install external configuration sources.",
"fix": "Attempt to automatically fix the given alert.",
}
Expand All @@ -40,6 +41,7 @@ var Actions = map[string]func(args []string, flags *core.CLIFlags) error{
"ls-config": printConfig,
"ls-metrics": printMetrics,
"ls-dirs": printDirs,
"ls-vars": printVars,
"sync": sync,

// private
Expand Down Expand Up @@ -237,6 +239,18 @@ func runRule(args []string, _ *core.CLIFlags) error {
return nil
}

func printVars(_ []string, _ *core.CLIFlags) error {
tableData := pterm.TableData{
{"Variable", "Description"},
}

for v, info := range core.ConfigVars {
tableData = append(tableData, []string{pterm.Gray(v), info})
}

return pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
}

func printDirs(_ []string, _ *core.CLIFlags) error {
styles, _ := core.DefaultStylesPath()

Expand All @@ -263,9 +277,9 @@ func printDirs(_ []string, _ *core.CLIFlags) error {

tableData := pterm.TableData{
{"Asset", "Default Location", "Found"},
{"StylesPath", styles, stylesFound},
{".vale.ini", cfg, configFound},
{"vale-native", nativeExe, nativeFound},
{pterm.Gray("StylesPath"), styles, stylesFound},
{pterm.Gray(".vale.ini"), cfg, configFound},
{pterm.Gray("vale-native"), nativeExe, nativeFound},
}

return pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
Expand Down
12 changes: 12 additions & 0 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/adrg/xdg"
"github.com/bmatcuk/doublestar/v4"
"github.com/errata-ai/ini"
"github.com/pterm/pterm"

"github.com/errata-ai/vale/v3/internal/glob"
)
Expand Down Expand Up @@ -43,6 +44,12 @@ var (
// configuration files.
var ConfigDirs = []string{VocabDir, DictDir, TmplDir, IgnoreDir}

// ConfigVars is a list of all supported environment variables.
var ConfigVars = map[string]string{
"VALE_CONFIG_PATH": fmt.Sprintf("Override the default search process by specifying a %s file.", pterm.Gray(".vale.ini")),
"VALE_STYLES_PATH": fmt.Sprintf("Specify the location of the default %s.", pterm.Gray("StylesPath")),
}

// ConfigNames is a list of all possible configuration file names.
//
// NOTE: This is leftover from the early days of Vale; we have now standardized
Expand Down Expand Up @@ -81,10 +88,15 @@ func DefaultConfig() (string, error) {
// NOTE: the default styles directory is only used if neither the
// project-specific nor the global configuration file specify a `StylesPath`.
func DefaultStylesPath() (string, error) {
if fromEnv, hasEnv := os.LookupEnv("VALE_STYLES_PATH"); hasEnv {
return fromEnv, nil
}

styles, err := xdg.DataFile("vale/styles/config.yml")
if err != nil {
return "", fmt.Errorf("failed to find default styles: %w", err)
}

return filepath.Dir(styles), nil
}

Expand Down

0 comments on commit 2139c41

Please sign in to comment.