Skip to content

Commit 71c0258

Browse files
committed
refactor: support JSON in ls-dirs
1 parent a270343 commit 71c0258

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cmd/vale/command.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,16 @@ func runRule(args []string, _ *core.CLIFlags) error {
243243
return nil
244244
}
245245

246-
func printVars(_ []string, _ *core.CLIFlags) error {
246+
func printVars(_ []string, flags *core.CLIFlags) error {
247+
if flags.Output == "JSON" {
248+
var out = map[string]string{}
249+
for name := range core.ConfigVars {
250+
value, _ := os.LookupEnv(name)
251+
out[name] = value
252+
}
253+
return printJSON(out)
254+
}
255+
247256
tableData := pterm.TableData{
248257
{"Variable", "Description", "Value"},
249258
}
@@ -259,7 +268,7 @@ func printVars(_ []string, _ *core.CLIFlags) error {
259268
return pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
260269
}
261270

262-
func printDirs(_ []string, _ *core.CLIFlags) error {
271+
func printDirs(_ []string, flags *core.CLIFlags) error {
263272
styles, _ := core.DefaultStylesPath()
264273

265274
stylesFound := pterm.FgGreen.Sprint("✓")
@@ -283,6 +292,14 @@ func printDirs(_ []string, _ *core.CLIFlags) error {
283292
nativeFound = pterm.FgRed.Sprint("✗")
284293
}
285294

295+
if flags.Output == "JSON" {
296+
return printJSON(map[string]string{
297+
"StylesPath": styles,
298+
".vale.ini": cfg,
299+
"vale-native": nativeExe,
300+
})
301+
}
302+
286303
tableData := pterm.TableData{
287304
{"Asset", "Default Location", "Found"},
288305
{toCodeStyle("StylesPath"), styles, stylesFound},

0 commit comments

Comments
 (0)