Skip to content

Commit

Permalink
fix(cli): add better help output describing --printer
Browse files Browse the repository at this point in the history
The default value was not properly being shown, and there was no example showing what alternate printers there were (such as `prettier`).
  • Loading branch information
eventualbuddha committed Apr 19, 2018
1 parent cbd8b9f commit e7b245e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import * as realFs from 'fs';
import getStream = require('get-stream');
import { basename } from 'path';
import CLIEngine from './CLIEngine';
import Config, { Printer } from './Config';
import Config from './Config';
import Options, { Command } from './Options';
import { SourceTransformResult } from './TransformRunner';

function optionAnnotation(
value: boolean | Array<string> | Map<string, object>
value: boolean | Array<string> | Map<string, object> | string
): string {
if (Array.isArray(value) || value instanceof Map) {
return ' (allows multiple)';
} else if (typeof value === 'boolean') {
return ` (default: ${value ? 'on' : 'off'})`;
} else if (typeof value === 'string') {
return ` (default: ${value})`;
} else {
return '';
}
Expand Down Expand Up @@ -51,8 +53,8 @@ OPTIONS
defaults.findBabelConfig
)}.
--printer PRINTER Specify which printer to use${optionAnnotation(
Printer[defaults.printer]
)}
defaults.printer
)}.
-s, --stdio Read source from stdin and print to stdout${optionAnnotation(
defaults.stdio
)}.
Expand Down Expand Up @@ -82,6 +84,9 @@ EXAMPLES
}
EOS
# Reprint modified files with prettier.
$ ${$0} --printer prettier -p some-plugin src/
# Pass options to a plugin.
$ ${$0} -p ./a.js -o a='{"foo":true}' src/
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"strictNullChecks": true,
"declaration": true
},
"exclude": [
"test/fixtures/**/*.ts"
]
}
"exclude": ["test/fixtures/**/*.ts"],
"compileOnSave": true
}

0 comments on commit e7b245e

Please sign in to comment.