Skip to content

Commit

Permalink
feat: run command match when only one exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jul 20, 2022
1 parent 39d5cb4 commit ab519b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/hooks/incomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Hook, toConfiguredId, toStandardizedId } from '@oclif/core';
import { Hook, toConfiguredId, toStandardizedId, Interfaces } from '@oclif/core';
import { Prompter } from '@salesforce/sf-plugins-core';

const hook: Hook.CommandIncomplete = async function ({ config, matches, argv }) {
async function determineCommand(config: Interfaces.Config, matches: Interfaces.Command.Loadable[]): Promise<string> {
if (matches.length === 1) return matches[0].id;
const prompter = new Prompter();
const { command } = await prompter.timedPrompt<{ command: string }>([
{
Expand All @@ -19,6 +20,12 @@ const hook: Hook.CommandIncomplete = async function ({ config, matches, argv })
},
]);

return command;
}

const hook: Hook.CommandIncomplete = async function ({ config, matches, argv }) {
const command = await determineCommand(config, matches);

if (argv.includes('--help') || argv.includes('-h')) {
return config.runCommand('help', [toStandardizedId(command, config)]);
}
Expand Down

0 comments on commit ab519b8

Please sign in to comment.