Command line call help text from inside handler
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza con el constructor de línea de comandos de Program y BarcodeCommand.BarcodeCommandHandler.InvokeAsync que se muestran en la incidencia. Determina cómo debe mostrar ayuda el comando cuando se invoca Barcode sin --list, preservando al mismo tiempo el comportamiento de Barcode --list; se considerará terminado cuando la estructura de comandos documentada funcione tal como se describe.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hello,
I hope you can help me. I am trying to create a command line application, but I am having trouble with the handling of the commands.
I have a command: Barcode. This command has an option: --list.
When Barcode is called, I want the command to display the help text.
When --list is added, I want it to do something.
However I am running into the issue that I cant call the help from inside the command handler. Is there a way to do this? In my main project I have DI injection set up, but I wouldn't know what I would have to inject to get to the help part of the command.
Here is a simplifyed bit of code showing what I want to do:
using Microsoft.Extensions.Hosting;
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Hosting;
using System.CommandLine.Parsing;
using UtTools.Controller.Commands.Barcode;
namespace UtToolsCommandLineTest
{
internal class Program
{
static void Main(string[] args)
{
RootCommand root = new RootCommand("Root");
root.AddCommand(new BarcodeCommand());
CommandLineBuilder builder = new CommandLineBuilder(root)
.UseDefaults()
.UseHost(_ => Host.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostContext, config) =>
{
}),
(builder) =>
{
builder.ConfigureServices(services =>
{
});
builder.UseCommandHandler<BarcodeCommand, BarcodeCommand.BarcodeCommandHandler>();
});
builder.Build().InvokeAsync(args);
}
}
}
using System.CommandLine;
using System.CommandLine.Help;
using System.CommandLine.Invocation;
namespace UtTools.Controller.Commands.Barcode
{
internal class BarcodeCommand : Command
{
public BarcodeCommand(string name = "Barcode", string description = "The base command for generating ccsg and q13 barcodes.") : base(name, description)
{
Option<bool> listOption = new Option<bool>(
aliases: new string[] { "--list", "-l" },
description: "List all available barcodes");
AddOption(listOption);
}
public class BarcodeCommandHandler : ICommandHandler
{
public bool List { get; set; }
public BarcodeCommandHandler()
{
}
public int Invoke(InvocationContext context)
{
return InvokeAsync(context).GetAwaiter().GetResult();
}
public Task<int> InvokeAsync(InvocationContext context)
{
if(!List)
{
/////////////////////////////////
// Should call the help text //
/////////////////////////////////
return Task.FromResult(1);
}
// Do stuff
return Task.FromResult(0);
}
}
}
}
The end goal is a command like this:
Barcode
├── --List Show all barcodes available
├──Generate
├── --OutputDirectoryPath The output directory
├── --Name
├──All Generate all barcodes
├── --OutputDirectoryPath The output directory
Thanks for any help you can give!
- Lenguaje dominante
- C#
- Estrellas
- 3.7k
- Forks
- 434
- Merge medio
- 6 h 27 min
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/command-line-api
-
German localization is incompletePosiblemente ocupada @b-v-d-e-v la tomó hace 18 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
dotnet/command-line-api#2852 ·
Los mantenedores suelen responder en 1 día
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translatedPosiblemente ocupada @JPBlanc la tomó hace 116 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
dotnet/command-line-api#2822 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
dotnet/command-line-api#2792 · 2 comentarios · 16 reacciones ·
Los mantenedores suelen responder en 1 día
-
`Argument.Arity` modify internal state on first get access.Posiblemente ocupada @zjdangge la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
dotnet/command-line-api#2704 ·
Los mantenedores suelen responder en 1 día
-
GetCompletions should check exit code of invoked applicationPosiblemente ocupada @baradgur la tomó hace 1287 días. AbiertoArea-Completions bug help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/command-line-api#2137 · 1 comentario · 3 reacciones ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/command-line-api
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
[Docs] README/PRIVACY still name AppCenter although v1.5.6.0+ uses the Microsoft Store Services SDKAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
swisstopo/swissgeol-boreholes-suite#3086 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: wiki jump bugAbiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
frontend
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Altinn/altinn-studio#21355 ·
Los mantenedores suelen responder en 1 día