Command line call help text from inside handler
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu với trình tạo dòng lệnh của Program và BarcodeCommand.BarcodeCommandHandler.InvokeAsync được trình bày trong issue. Xác định cách lệnh phải hiển thị trợ giúp khi Barcode được gọi mà không có --list, đồng thời giữ nguyên hành vi của Barcode --list; hoàn thành khi cấu trúc lệnh được tài liệu hóa hoạt động như mô tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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!
- Ngôn ngữ chính
- C#
- Star
- 3.7k
- Fork
- 434
- Merge trung bình
- 6 giờ 27 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/command-line-api
-
German localization is incompleteCó thể đã có người làm @b-v-d-e-v đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2852 ·
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translatedCó thể đã có người làm @JPBlanc đã nhận 114 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2822 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2792 · 2 bình luận · 16 reaction ·
-
`Argument.Arity` modify internal state on first get access.Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2704 ·
-
GetCompletions should check exit code of invoked applicationCó thể đã có người làm @baradgur đã nhận 1286 ngày trước. Đang mởArea-Completions bug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/command-line-api#2137 · 1 bình luận · 3 reaction ·
Tất cả issue của dotnet/command-line-api
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
nightscout/nocturne#2135 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Devolutions/UniGetUI#5541 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[aw] PR Iteration Agent 🔧 failedĐang mởagentic-workflows Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[誤判定]Đang mởlinux アプリ: ブラウザー 再現済み 要トリアージ 誤判定
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
yksr-melt/Meltype#853 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày