public OrganizationCommand(CliContext context) : base(context, "organization", "Choose organization") { AddAlias("org"); AddArgument(new Argument <string>("organization-slug")); }
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); }
public SubmitCommand(CliContext context) : base(context, "submit", "Submit exercise(s)") { AddArgument(new Argument <DirectoryInfo>("directory") { Description = "Directory of the exercise" }); Handler = CommandHandler.Create <DirectoryInfo>(HandleSubmitAsync); }
public ExercisesCommand(CliContext context) : base(context, "exercises", "List and update exercises for a specific course") { //TODO: If no CurrentCourse nor specified course to fetch exercises => info msg AddOption(new Option <string>("--course", "Name of the course")); var updateCommand = new Command("update", "Update exercises") { Handler = CommandHandler.Create(UpdateExercisesAsync) }; AddCommand(updateCommand); }
private int?Execute(CliContext context) { // Get configuration and input from context ApplicationConfiguration _configuration = context.Configuration; CommandInput input = context.Input; // Handle interactive directive not supported in application if (!_configuration.IsInteractiveModeAllowed && input.IsInteractiveDirectiveSpecified) { throw EndUserTypinExceptions.InteractiveModeNotSupported(); } return(null); }
public DownloadCommand(CliContext context) : base(context, "download", "Download exercises from TMC server") { AddOption(new Option <IEnumerable <int> >("--exercise-id", "Download specified course by its unique identifier")); AddOption(new Option <string>("--course", "Download exercises by course name")); AddOption(new Option <int>("--course-id", "Download exercises by course identfier")); AddOption(new Option <DirectoryInfo>("--output", "If specified, the downloaded files ")); AddOption(new Option <bool>("--all", "Download every found exercise, whether it is already completed or not")); AddOption(new Option <bool>("--overwrite", "If the downloaded files already exist in the output directory, it will be overwritten.")); Handler = CommandHandler.Create <IEnumerable <int> >(HandleDownloadAsync); }
private int?Execute(CliContext context) { CommandInput input = context.Input; // Get command schema from context CommandSchema commandSchema = context.CommandSchema; // Version option if (commandSchema.IsVersionOptionAvailable && input.IsVersionOptionSpecified) { context.Console.Output.WriteLine(context.Metadata.VersionText); return(ExitCodes.Success); } return(null); }
public async Task HandleAsync(ICliContext context, CommandPipelineHandlerDelegate next, CancellationToken cancellationToken) { //Get current CLI mode and input directives Type currentModeType = _applicationLifetime.CurrentModeType !; IReadOnlyList <DirectiveInput> directives = context.Input.Directives; //Initialize collections List <IDirective> directivesInstances = new List <IDirective>(); List <IPipelinedDirective> pipelinedDirectivesInstances = new List <IPipelinedDirective>(); //Process directive input foreach (DirectiveInput directiveInput in directives) { // Try to get the directive matching the input or fallback to default DirectiveSchema directive = context.RootSchema.TryFindDirective(directiveInput.Name) ?? throw ArgumentBindingExceptions.UnknownDirectiveName(directiveInput); // Handle interactive directives not supported in current mode if (!directive.CanBeExecutedInMode(currentModeType)) { throw ModeEndUserExceptions.DirectiveExecutedInInvalidMode(directive, currentModeType); } // Get directive instance IDirective instance = (IDirective)_serviceProvider.GetRequiredService(directive.Type); //Initialize directive await instance.OnInitializedAsync(cancellationToken); //Add directive to list directivesInstances.Add(instance); if (directive.IsPipelinedDirective && instance is IPipelinedDirective pd) { pipelinedDirectivesInstances.Add(pd); } } //Set directives lists in context CliContext internalCliContext = (CliContext)context; internalCliContext.Directives = directivesInstances; internalCliContext.PipelinedDirectives = pipelinedDirectivesInstances; await next(); }
private int?Execute(CliContext context) { // Get command schema from context CommandSchema commandSchema = context.CommandSchema; // Get command instance (also used in help text) 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) { // Get input and command schema from context CommandInput input = context.Input; CommandSchema commandSchema = context.CommandSchema; // Help option if ((commandSchema.IsHelpOptionAvailable && input.IsHelpOptionSpecified) || (commandSchema == StubDefaultCommand.Schema && !input.Parameters.Any() && !input.Options.Any())) { IHelpWriter helpTextWriter = new DefaultHelpWriter(context); helpTextWriter.Write(commandSchema, context.CommandDefaultValues); return(ExitCodes.Success); } return(null); }
public LoginCommand(CliContext context) : base(context, "login", "Login to TMC server") { AddArgument(new Argument <string>("username") { Description = "TMC Username" }); //TODO: Option AddArgument(new Argument <string>("password") { Description = "Password of the user" }); //TODO: Option AddArgument(new Argument <string>("organization") { Description = "MC Organization" }); //TODO: Option Handler = CommandHandler.Create <string, string, string>(LoginAsync); }
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); }
public virtual void Configure(CommandLineApplication command) { var prefixOutput = command.Option("--prefix-output", Resources.PrefixDescription); var quiet = command.Option("-q|--quiet", Resources.QuietDescription); var verbose = command.VerboseOption(); command.OnExecute( () => { IsQuiet = quiet.HasValue(); IsVerbose = verbose.HasValue() || CliContext.IsGlobalVerbose(); ReporterExtensions.PrefixOutput = prefixOutput.HasValue(); // Update the reporter now that we know the option values. Reporter = new ConsoleReporter(_console, IsVerbose, IsQuiet); Validate(); return(Execute()); }); }
private async Task <int> Execute(CliContext context) { //Get input and command schema from context CommandInput input = context.Input; CommandSchema commandSchema = context.CommandSchema; // Execute directives if (!await ProcessDefinedDirectives(context)) { return(ExitCodes.Success); } // Get command instance from context and bind arguments ICommand instance = context.Command; commandSchema.Bind(instance, input, _optionFallbackProvider); // Execute command await instance.ExecuteAsync(context.Console); return(context.ExitCode ??= ExitCodes.Success); }
private int?Execute(CliContext context) { //Get configuration and input from context ApplicationConfiguration _configuration = context.Configuration; CommandInput input = context.Input; // Get command schema from context CommandSchema commandSchema = context.CommandSchema; // Handle commands not supported in normal mode if (!_configuration.IsInteractiveModeAllowed && commandSchema.InteractiveModeOnly) { throw EndUserTypinExceptions.InteractiveOnlyCommandButThisIsNormalApplication(commandSchema); } // Handle commands supported only in interactive mode when interactive mode was not started if (_configuration.IsInteractiveModeAllowed && commandSchema.InteractiveModeOnly && !(context.IsInteractiveMode || input.IsInteractiveDirectiveSpecified)) { throw EndUserTypinExceptions.InteractiveOnlyCommandButInteractiveModeNotStarted(commandSchema); } return(null); }
public CliExecutionScope(CliContext cliContext, IServiceScopeFactory serviceScopeFactory) { Context = cliContext; ServiceScope = serviceScopeFactory.CreateScope(); }
private static IReporter CreateReporter(bool verbose, bool quiet, IConsole console) => new PrefixConsoleReporter("watch : ", console, verbose || CliContext.IsGlobalVerbose(), quiet);
/// <summary> /// Initializes an instance of <see cref="ScopeDirective"/>. /// </summary> public ScopeDirective(ICliContext cliContext) { _cliContext = (CliContext)cliContext; }
public LogoutCommand(CliContext context) : base(context, "logout", "Logout from TMC server") { }
private static IReporter CreateReporter(bool verbose, bool quiet, IConsole console) { return(new ConsoleReporter(console, verbose || CliContext.IsGlobalVerbose(), quiet)); }
protected TMCCommand(CliContext context, string name, string?description = default) : base(name, description) { Context = context; }
public CoursesCommand(CliContext context) : base(context, "courses", "Show the available courses") { AddArgument(new Argument <string>("organization")); }