private int?Execute(CliContext context) { RootSchema root = context.RootSchema; CommandInput input = context.Input; // Try to get the command matching the input or fallback to default CommandSchema commandSchema = root.TryFindCommand(input.CommandName) ?? StubDefaultCommand.Schema; // TODO: is the problem below still valid? // TODO: is it poossible to overcome this (related to [!]) limitation of new mode system // Forbid to execute real default command in interactive mode without [!] directive. //if (!(commandSchema.IsHelpOptionAvailable && input.IsHelpOptionSpecified) && // _applicationLifetime.CurrentModeType == typeof(InteractiveMode) && // commandSchema.IsDefault && !hasDefaultDirective) //{ // commandSchema = StubDefaultCommand.Schema; //} // Update CommandSchema context.CommandSchema = commandSchema; // Get command instance (default values are used in help so we need command instance) ICommand instance = GetCommandInstance(commandSchema); context.Command = instance; // To avoid instantiating the command twice, we need to get default values // before the arguments are bound to the properties IReadOnlyDictionary <ArgumentSchema, object?> defaultValues = commandSchema.GetArgumentValues(instance); context.CommandDefaultValues = defaultValues; return(null); }
private int?Execute(CliContext context) { RootSchema root = context.RootSchema; CommandInput input = context.Input; // Try to get the command matching the input or fallback to default bool hasDefaultDirective = input.HasDirective(BuiltInDirectives.Default); CommandSchema command = root.TryFindCommand(input.CommandName, hasDefaultDirective) ?? StubDefaultCommand.Schema; // Forbid to execute real default command in interactive mode without [!] directive. if (!(command.IsHelpOptionAvailable && input.IsHelpOptionSpecified) && context.IsInteractiveMode && command.IsDefault && !hasDefaultDirective) { command = StubDefaultCommand.Schema; } // Update CommandSchema context.CommandSchema = command; return(null); }