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

fix(cli): clarify usage of --format #2575

Merged
merged 1 commit into from
Jan 17, 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
27 changes: 24 additions & 3 deletions docs/guides/2-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ Other options include:
--help Show help [boolean]
-e, --encoding text encoding to use
[string] [choices: "utf8", "ascii", "utf-8", "utf16le", "ucs2", "ucs-2", "base64", "latin1"] [default: "utf8"]
-f, --format formatters to use for outputting results, more than one can be given joining them with
a comma
[string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"]
-f, --format formatters to use for outputting results, more than one can be provided by using
multiple flags
[string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"]
[default: "stylish"]
-o, --output where to output results, can be a single file name, multiple "output.<format>" or
missing to print to stdout [string]
Expand Down Expand Up @@ -176,6 +176,27 @@ title: Example

<!-- type: tab-end -->

### Multiple formatters

If you wish to output results in multiple formats, you can do so by passing multiple `-f` flags.
In order to output results in multiple formats, you must also pass the `-o` flag with a filename for each format.

```bash
spectral lint "specs/**/*.yaml" -f json -f junit -o.json results.json -o.junit junit.xml
```

You can also pipe an output to stdout.

```bash
spectral lint "specs/**/*.yaml" -f stylish -f junit -o.junit junit.xml -o.stylish "<stdout>"
```

It's possible to output each format to stdout.

```bash
spectral lint "specs/**/*.yaml" -f text -f stylish -o.text "<stdout>" -o.stylish "<stdout>"
```

## Proxying

To have requests made from Spectral be proxied through a server, you'd need to specify the `PROXY` environment variable:
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"pony-cause": "^1.0.0",
"stacktracey": "^2.1.7",
"tslib": "^2.3.0",
"yargs": "17.3.1"
"yargs": "~17.7.2"
},
"devDependencies": {
"@types/es-aggregate-error": "^1.0.2",
Expand All @@ -65,8 +65,7 @@
},
"pkg": {
"scripts": [
"./dist/**/*.js",
"../../node_modules/vm2/lib/*.js"
"./dist/**/*.js"
],
"assets": [
"./dist/**/*.json",
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const lintCommand: CommandModule = {
},
})
.middleware((argv: Dictionary<unknown>) => {
const formats = argv.format as string[] & { 0: string };
const formats = argv.format as [string, ...string[]];
if (argv.output === void 0) {
argv.output = { [formats[0]]: '<stdout>' };
} else if (typeof argv.output === 'string') {
Expand Down Expand Up @@ -101,7 +101,8 @@ const lintCommand: CommandModule = {
},
format: {
alias: 'f',
description: 'formatters to use for outputting results, more than one can be given joining them with a comma',
description:
'formatters to use for outputting results, more than one can be provided by using multiple flags',
choices: formatOptions,
default: OutputFormat.STYLISH,
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
rules: {}
}
====command-nix====
{bin} lint ./*oops.{yml,yaml,json} --fail-on-unmatched-globs --ruleset "{asset:ruleset}"
{bin} lint "./*oops.{yml,yaml,json}" --fail-on-unmatched-globs --ruleset "{asset:ruleset}"
====status====
2
====stderr====
Expand Down
2 changes: 1 addition & 1 deletion test-harness/scenarios/help-no-document.scenario
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Options:
--version Show version number [boolean]
--help Show help [boolean]
-e, --encoding text encoding to use [string] [choices: "utf8", "ascii", "utf-8", "utf16le", "ucs2", "ucs-2", "base64", "latin1"] [default: "utf8"]
-f, --format formatters to use for outputting results, more than one can be given joining them with a comma [string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"] [default: "stylish"]
-f, --format formatters to use for outputting results, more than one can be provided by using multiple flags [string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"] [default: "stylish"]
-o, --output where to output results, can be a single file name, multiple "output.<format>" or missing to print to stdout [string]
--stdin-filepath path to a file to pretend that stdin comes from [string]
--resolver path to custom json-ref-resolver instance [string]
Expand Down
2 changes: 1 addition & 1 deletion test-harness/scenarios/proxy-agent.scenario
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Requests for $refs are proxied when PROXY env variable is set
foo:
$ref: http://localhost:3002/foo.json#/ref
====env====
PROXY=http://localhost:3001
PROXY=http://127.0.0.1:3001
====asset:ruleset====
module.exports = {
rules: {}
Expand Down
2 changes: 1 addition & 1 deletion test-harness/scenarios/strict-options.scenario
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Options:
--version Show version number [boolean]
--help Show help [boolean]
-e, --encoding text encoding to use [string] [choices: "utf8", "ascii", "utf-8", "utf16le", "ucs2", "ucs-2", "base64", "latin1"] [default: "utf8"]
-f, --format formatters to use for outputting results, more than one can be given joining them with a comma [string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"] [default: "stylish"]
-f, --format formatters to use for outputting results, more than one can be provided by using multiple flags [string] [choices: "json", "stylish", "junit", "html", "text", "teamcity", "pretty", "github-actions", "sarif"] [default: "stylish"]
-o, --output where to output results, can be a single file name, multiple "output.<format>" or missing to print to stdout [string]
--stdin-filepath path to a file to pretend that stdin comes from [string]
--resolver path to custom json-ref-resolver instance [string]
Expand Down
Loading