Skip to content

Commit c346e0b

Browse files
rexxarsbjoerge
authored andcommitted
[cli] Fix issue where command group roots would not list commands (#109)
1 parent 8cbee5b commit c346e0b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/@sanity/cli/src/CommandRunner.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,20 @@ export default class CommandRunner {
8080
commandRunner: this
8181
}
8282

83+
if (command.isGroupRoot) {
84+
return context.output.print(generateCommandsDocumentation(
85+
this.commandGroups,
86+
command.name
87+
))
88+
}
89+
8390
if (typeof command.action !== 'function') {
8491
const cmdName = command.name || commandOrGroup || '<unknown>'
8592
debug(`Command "${cmdName}" doesnt have a valid "action"-property, showing help`)
93+
const groupName = command.group && command.group !== 'default' ? command.group : null
8694
return context.output.print(generateCommandDocumentation(
8795
command,
88-
command.group && command.group !== 'default' ? command.group : null,
96+
groupName,
8997
subCommandName
9098
))
9199
}

packages/@sanity/cli/src/commands/help/showHelp.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default (args, context) => {
4545
throw new Error(noSuchCommandText(subCommandName, commandName, commandGroups))
4646
}
4747

48+
debug('Subcommand "%s" for group "%s" found, showing help', subCommandName, commandName)
4849
context.output.print(generateCommandDocumentation(
4950
subCommand.command,
5051
commandName,

packages/@sanity/core/src/commands/documents/queryDocumentsCommand.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
const colorizeJson = require('../../util/colorizeJson')
22

3+
const help = `
4+
Runs a query against the projects configured dataset. Specify --pretty to get
5+
colorized JSON output. Example:
6+
7+
sanity documents query '*[_type == "movie"][0...5]'
8+
9+
Will fetch 5 documents of type "movie"
10+
`
11+
312
export default {
413
name: 'query',
514
group: 'documents',
615
signature: '[QUERY]',
716
description: 'Query for documents',
17+
helpText: help,
818
action: async (args, context) => {
919
const {apiClient, output, chalk} = context
1020
const {pretty} = args.extOptions

0 commit comments

Comments
 (0)