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

Reformat code with Prettier #2180

Merged
merged 1 commit into from Apr 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions eslint.config.js
Expand Up @@ -14,20 +14,17 @@ const tseslintConfigs = tseslint.config(
languageOptions: {
parserOptions: { project: './tsconfig.js.json' },
},
extends: [
...tseslint.configs.recommended,
],
extends: [...tseslint.configs.recommended],
rules: {
'@typescript-eslint/no-var-requires': 'off', // (tseslint does not autodetect commonjs context )
},
}, {
},
{
files: tsconfigTsFiles,
languageOptions: {
parserOptions: { project: './tsconfig.ts.json' },
},
extends: [
...tseslint.configs.recommended,
],
extends: [...tseslint.configs.recommended],
},
);

Expand Down Expand Up @@ -59,17 +56,20 @@ module.exports = [
files: ['**/*.test.{js,mjs,cjs}'],
rules: {
'no-unused-vars': 'off', // lots in tests, minimise churn for now
}
},
},
{
files: [...tsconfigTsFiles, ...tsconfigJsFiles],
rules: {
'@typescript-eslint/ban-ts-comment': ['error', {
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': true,
'ts-check': true,
}],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': true,
'ts-check': true,
},
],
},
},
];
2 changes: 1 addition & 1 deletion esm.mjs
Expand Up @@ -12,5 +12,5 @@ export const {
Command,
Argument,
Option,
Help
Help,
} = commander;
2 changes: 1 addition & 1 deletion examples/action-this.js
Expand Up @@ -9,7 +9,7 @@ program
.command('serve')
.argument('<script>')
.option('-p, --port <number>', 'port number', 80)
.action(function() {
.action(function () {
console.error('Run script %s on port %s', this.args[0], this.opts().port);
});

Expand Down
15 changes: 13 additions & 2 deletions examples/arguments-extra.js
Expand Up @@ -6,8 +6,19 @@ const commander = require('commander');
const program = new commander.Command();

program
.addArgument(new commander.Argument('<drink-size>', 'drink cup size').choices(['small', 'medium', 'large']))
.addArgument(new commander.Argument('[timeout]', 'timeout in seconds').default(60, 'one minute'))
.addArgument(
new commander.Argument('<drink-size>', 'drink cup size').choices([
'small',
'medium',
'large',
]),
)
.addArgument(
new commander.Argument('[timeout]', 'timeout in seconds').default(
60,
'one minute',
),
)
.action((drinkSize, timeout) => {
console.log(`Drink size: ${drinkSize}`);
console.log(`Timeout (s): ${timeout}`);
Expand Down
12 changes: 9 additions & 3 deletions examples/configure-help.js
Expand Up @@ -8,11 +8,17 @@ const program = new commander.Command();

program.configureHelp({
sortSubcommands: true,
subcommandTerm: (cmd) => cmd.name() // Just show the name, instead of short usage.
subcommandTerm: (cmd) => cmd.name(), // Just show the name, instead of short usage.
});

program.command('zebra <herd-size>', 'African equines with distinctive black-and-white striped coats');
program.command('aardvark [colour]', 'medium-sized, burrowing, nocturnal mammal');
program.command(
'zebra <herd-size>',
'African equines with distinctive black-and-white striped coats',
);
program.command(
'aardvark [colour]',
'medium-sized, burrowing, nocturnal mammal',
);
program
.command('beaver', 'large, semiaquatic rodent')
.option('--pond')
Expand Down
20 changes: 8 additions & 12 deletions examples/configure-output.js
Expand Up @@ -6,19 +6,15 @@ function errorColor(str) {
return `\x1b[31m${str}\x1b[0m`;
}

program
.configureOutput({
// Visibly override write routines as example!
writeOut: (str) => process.stdout.write(`[OUT] ${str}`),
writeErr: (str) => process.stdout.write(`[ERR] ${str}`),
// Output errors in red.
outputError: (str, write) => write(errorColor(str))
});
program.configureOutput({
// Visibly override write routines as example!
writeOut: (str) => process.stdout.write(`[OUT] ${str}`),
writeErr: (str) => process.stdout.write(`[ERR] ${str}`),
// Output errors in red.
outputError: (str, write) => write(errorColor(str)),
});

program
.version('1.2.3')
.option('-c, --compress')
.command('sub-command');
program.version('1.2.3').option('-c, --compress').command('sub-command');

program.parse();

Expand Down
8 changes: 3 additions & 5 deletions examples/custom-command-class.js
Expand Up @@ -32,11 +32,9 @@ program
inpectCommand(command);
});

program
.command('build <target>')
.action((buildTarget, options, command) => {
inpectCommand(command);
});
program.command('build <target>').action((buildTarget, options, command) => {
inpectCommand(command);
});

program.parse();

Expand Down
10 changes: 6 additions & 4 deletions examples/custom-help
Expand Up @@ -6,13 +6,15 @@
const { Command } = require('commander');
const program = new Command();

program
.option('-f, --foo', 'enable some foo');
program.option('-f, --foo', 'enable some foo');

program.addHelpText('after', `
program.addHelpText(
'after',
`
Example call:
$ custom-help --help`);
$ custom-help --help`,
);

program.parse(process.argv);

Expand Down
7 changes: 5 additions & 2 deletions examples/custom-help-text.js
Expand Up @@ -19,10 +19,13 @@ program
program
.command('extra')
.addHelpText('before', 'Note: the extra command does not do anything')
.addHelpText('after', `
.addHelpText(
'after',
`
Examples:
awesome extra --help
awesome help extra`);
awesome help extra`,
);

program.parse();

Expand Down
16 changes: 12 additions & 4 deletions examples/deploy
Expand Up @@ -25,11 +25,19 @@ program
.option('-e, --exec_mode <mode>', 'Which exec mode to use', 'fast')
.action((script, options) => {
console.log('read config from %s', program.opts().config);
console.log('exec "%s" using %s mode and config %s', script, options.exec_mode, program.opts().config);
}).addHelpText('after', `
console.log(
'exec "%s" using %s mode and config %s',
script,
options.exec_mode,
program.opts().config,
);
})
.addHelpText(
'after',
`
Examples:
$ deploy exec sequential
$ deploy exec async`
$ deploy exec async`,
);

program.parse(process.argv);
6 changes: 4 additions & 2 deletions examples/global-options-added.js
Expand Up @@ -23,13 +23,15 @@ class MyRootCommand extends Command {

const program = new MyRootCommand();

program.command('print')
program
.command('print')
.option('--a4', 'Use A4 sized paper')
.action((options) => {
console.log('print options: %O', options);
});

program.command('serve')
program
.command('serve')
.option('-p, --port <number>', 'port number for server')
.action((options) => {
console.log('serve options: %O', options);
Expand Down
6 changes: 2 additions & 4 deletions examples/global-options-nested.js
Expand Up @@ -9,17 +9,15 @@
const { Command } = require('commander');
const program = new Command();

program
.configureHelp({ showGlobalOptions: true })
.option('-g, --global');
program.configureHelp({ showGlobalOptions: true }).option('-g, --global');

program
.command('sub')
.option('-l, --local')
.action((options, cmd) => {
console.log({
opts: cmd.opts(),
optsWithGlobals: cmd.optsWithGlobals()
optsWithGlobals: cmd.optsWithGlobals(),
});
});

Expand Down
15 changes: 10 additions & 5 deletions examples/help-subcommands-usage.js
Expand Up @@ -6,19 +6,24 @@ const commander = require('commander');
// See also ./configure-help.js which shows configuring the subcommand list to have no usage at all
// and just the subcommand name.

const program = new commander.Command()
.configureHelp({ subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage() });
const program = new commander.Command().configureHelp({
subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage(),
});

program.command('make <FILENAME>')
program
.command('make <FILENAME>')
.usage('-root ROOTDIR [-abc] <FILENAME>')
.requiredOption('--root <ROOTDIR>')
.option('-a')
.option('-b')
.option('-c')
.summary('example command with custom usage')
.description('this full description is displayed in the full help and not in the list of subcommands');
.description(
'this full description is displayed in the full help and not in the list of subcommands',
);

program.command('serve <SERVICE>')
program
.command('serve <SERVICE>')
.option('--port <PORTNUMBER>')
.description('example command with default simple usage');

Expand Down
17 changes: 12 additions & 5 deletions examples/hook.js
Expand Up @@ -24,7 +24,9 @@ program
.hook('preAction', (thisCommand, actionCommand) => {
if (thisCommand.opts().trace) {
console.log('>>>>');
console.log(`About to call action handler for subcommand: ${actionCommand.name()}`);
console.log(
`About to call action handler for subcommand: ${actionCommand.name()}`,
);
console.log('arguments: %O', actionCommand.args);
console.log('options: %o', actionCommand.opts());
console.log('<<<<');
Expand All @@ -43,13 +45,18 @@ program
}
});

program.command('start')
program
.command('start')
.argument('[script]', 'script name', 'server.js')
.option('-d, --delay <seconds>', 'how long to delay before starting')
.addOption(new Option('-p, --port <number>', 'port number').default(8080).env('PORT'))
.action(async(script, options) => {
.addOption(
new Option('-p, --port <number>', 'port number').default(8080).env('PORT'),
)
.action(async (script, options) => {
if (options.delay) {
await new Promise(resolve => setTimeout(resolve, parseInt(options.delay) * 1000));
await new Promise((resolve) =>
setTimeout(resolve, parseInt(options.delay) * 1000),
);
}
console.log(`Starting ${script} on port ${options.port}`);
});
Expand Down
32 changes: 12 additions & 20 deletions examples/nestedCommands.js
Expand Up @@ -9,31 +9,23 @@ const program = new commander.Command();

// Add nested commands using `.command()`.
const brew = program.command('brew');
brew
.command('tea')
.action(() => {
console.log('brew tea');
});
brew
.command('coffee')
.action(() => {
console.log('brew coffee');
});
brew.command('tea').action(() => {
console.log('brew tea');
});
brew.command('coffee').action(() => {
console.log('brew coffee');
});

// Add nested commands using `.addCommand().
// The command could be created separately in another module.
function makeHeatCommand() {
const heat = new commander.Command('heat');
heat
.command('jug')
.action(() => {
console.log('heat jug');
});
heat
.command('pot')
.action(() => {
console.log('heat pot');
});
heat.command('jug').action(() => {
console.log('heat jug');
});
heat.command('pot').action(() => {
console.log('heat pot');
});
return heat;
}
program.addCommand(makeHeatCommand());
Expand Down
3 changes: 1 addition & 2 deletions examples/options-boolean-or-value.js
Expand Up @@ -7,8 +7,7 @@
const commander = require('commander');
const program = new commander.Command();

program
.option('-c, --cheese [type]', 'Add cheese with optional type');
program.option('-c, --cheese [type]', 'Add cheese with optional type');

program.parse(process.argv);

Expand Down