Skip to content

Commit b15734b

Browse files
committed
fix(commands): don't resolve the options service for option-less definitions
A definition with no declared options must be executable in a container that has no options service registered - manifest-loaded extension commands run in exactly that situation.
1 parent 94381ca commit b15734b

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

lib/common/services/command-definition-adapter.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ export function createCommandFromDefinition<
6565
// Resolved per call: the options service only holds parsed values once
6666
// validateOptions has run for this command.
6767
const buildContext = (args: string[]): ICommandContext<TSchema> => {
68-
const optionsService: any = targetInjector.resolve("options");
6968
const options: any = {};
70-
for (const optionName of optionNames) {
71-
options[optionName] = optionsService
72-
? optionsService[optionName]
73-
: undefined;
69+
// Only a definition that declares options may depend on the options
70+
// service being registered - a bare command must work without one.
71+
if (optionNames.length) {
72+
const optionsService: any = targetInjector.resolve("options");
73+
for (const optionName of optionNames) {
74+
options[optionName] = optionsService
75+
? optionsService[optionName]
76+
: undefined;
77+
}
7478
}
7579

7680
return { args, options };

0 commit comments

Comments
 (0)