Skip to content
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
11 changes: 11 additions & 0 deletions packages/core/bin/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ const COLLECTION = [
const ALIAS = { run: 'function' }

const COMMANDS = {
help: {
usage: 'help [command]',
desc: 'Show this help',
flags: [],
cli: [],
examples: [
['help', 'show this help'],
['help screenshot', 'show screenshot help']
]
},
login: {
usage: 'login',
desc: 'Save an API key from your Microlink account',
Expand Down Expand Up @@ -293,6 +303,7 @@ const commandList = Object.entries(COMMANDS)
const global = `Usage
${cmd('<url> [options]')}
${cmd('<product> <url|query> [options]')}
${cmd('help')}
${cmd('login')}
${cmd('logout')}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const run = async (argvInput, host) => {

const isTrace = trace || traceFull

if (!command) return showHelp()
if (!command || command === 'help') return showHelp(target)

if (command === 'login' || command === 'logout') {
if (help) return showHelp(command)
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ test('prints help with no arguments', async t => {
t.true(stdout.includes('logout'))
})

test('help command matches --help', async t => {
const { stdout: help } = await $('node', [bin, 'help'])
const { stdout: flag } = await $('node', [bin, '--help'])
t.is(help, flag)
})

test('help <product> matches product --help', async t => {
const { stdout: help } = await $('node', [bin, 'help', 'screenshot'])
const { stdout: flag } = await $('node', [bin, 'screenshot', '--help'])
t.is(help, flag)
})

test('prints command help for login', async t => {
const { stdout } = await $('node', [bin, 'login', '--help'])
t.true(stdout.includes('login'))
Expand Down