@@ -6,6 +6,7 @@ import { Injector } from "../di/injector";
66import { IDictionary , IDashedOption , IErrors } from "../declarations" ;
77import { ICommand } from "../definitions/commands" ;
88import { COMMAND_CONTEXT } from "../contracts/command-context" ;
9+ import { CommandsService } from "../contracts/commands-service" ;
910import {
1011 COMMAND_OWNER ,
1112 CommandRegistry ,
@@ -29,6 +30,7 @@ import {
2930 CommandOptionSpec ,
3031 CommandOptionType ,
3132 CommandOptionsSchema ,
33+ CommandReference ,
3234 DefinedCommand ,
3335 RegisterableCommand ,
3436 defineCommand ,
@@ -403,10 +405,9 @@ export function createCommandFromDefinition<
403405 return ;
404406 }
405407
406- const commandsService = targetInjector . get < ICommandsService > (
407- "commandsService" ,
408- { optional : true } ,
409- ) ;
408+ const commandsService = targetInjector . get ( CommandsService , {
409+ optional : true ,
410+ } ) ;
410411 if ( commandsService && commandsService . isExecutingInProcess ) {
411412 return ;
412413 }
@@ -543,40 +544,28 @@ const contextInjector = (): Injector =>
543544 getCurrentInjector ( ) || < Injector > ( < any > getRootInjector ( ) ) ;
544545
545546/**
546- * Runs a registered command in the current process. The command gets what a
547- * typed command line gives it — its declared options primed with their
548- * defaults, the arguments policy, `canExecute`, hooks and `postRun` — and a
549- * failure throws instead of exiting, so a process that has to keep running
550- * (`ns start`, dispatching a key shortcut) can catch it.
547+ * Convenience over `CommandsService.runCommand` for code that has no injected
548+ * service at hand, such as a key shortcut action or an inline handler; the
549+ * contract is the API, this only resolves it from the current context.
551550 */
552551export async function runCommand (
553- name : string ,
552+ command : CommandReference ,
554553 args : string [ ] = [ ] ,
555554) : Promise < void > {
556- const commandsService =
557- contextInjector ( ) . get < ICommandsService > ( "commandsService" ) ;
558-
559- await commandsService . executeCommandInProcess ( name , args ) ;
555+ await contextInjector ( ) . get ( CommandsService ) . runCommand ( command , args ) ;
560556}
561557
562558/**
563- * Asks a registered command whether it could run on `args`, without running it.
564- * The named command is resolved and its options primed exactly as `runCommand`
565- * does, and its own `canExecute` returns the verdict.
566- *
567- * This is how one command reuses another's precondition — `embed` asking
568- * whether `prepare` would run. The child resolves its own services, so nothing
569- * crosses between the two but the name and the arguments; pass only the
570- * arguments the child's own `arguments` policy accepts.
559+ * Convenience over `CommandsService.canExecuteCommand`, resolved from the
560+ * current context the way `runCommand` is.
571561 */
572562export async function canExecuteCommand (
573- name : string ,
563+ command : CommandReference ,
574564 args : string [ ] = [ ] ,
575565) : Promise < boolean > {
576- const commandsService =
577- contextInjector ( ) . get < ICommandsService > ( "commandsService" ) ;
578-
579- return commandsService . canExecuteCommandInProcess ( name , args ) ;
566+ return contextInjector ( )
567+ . get ( CommandsService )
568+ . canExecuteCommand ( command , args ) ;
580569}
581570
582571/**
0 commit comments