Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Return values from actions on Options?

未关闭
#2,768 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
csharp
领域
cli

调研方向

首先追踪 Option actions 的调用方式,以及它们的返回值如何通过顶层 Invoke 调用传递。将该行为与 Command actions 以及文档中对 --help 的处理方式进行比较,然后确定 Option actions 的预期 contract,以及什么样的行为或文档可以将该 issue 定义为已完成。

由索引模型根据 Issue 内容生成。

描述

I'm trying to work out the "right" way to use this library, and a very simple use case that puzzles me is "detect that --help was invoked, so we can terminate the application after handling arguments", and it is not really clear to me how that should be done.

My first thought was that I should attach an Action to the Option, and have that action return non-zero, which would propagate out to the top-level Invoke call. Then I'd check the return value there, and if non-zero, terminate the application.

But if an Option's action returns non-zero the return value just seems to be discarded.

I also noted that none of the documentation seems to use actions on Option objects, and that while actions on Command objects can just be lambdas, the ones on Option have to be a class derived from CommandLineAction. It kind of feels like Option actions are a bit half-baked? Are they not supposed to be used?

So two questions:

  1. what is the point of setting actions on an Option object? (And what is the point of being able to return an integer from those actions?)
  2. what is the intended way to detect that --help was invoked so you can terminate the application?
主要语言
C#
星标
3.7k
派生
434
平均合并
4 小时 46 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/command-line-api 的其他 Issue

查看 dotnet/command-line-api 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。