commandlineparser / commandlineparser/commandline

Implement --no-SOME_OPTION

オープン
#783 コメント 10 件 リアクション 1 件 担当者 0 名 GitHub で見る
good first issue help wanted
主要言語
C#
スター
4.8k
フォーク
478
PR マージ指標
30日以内にマージされた PR はありません

説明

I want these mutually exclusive options:

- --updateParts
- --not-updateParts

The default is to update parts, and it's disabled if the second flag is passed. The user needs to pass one flag or the other (so they don't get a behavior they didn't explicitly ask for).

Is there any way to do this? I had a go with this:

`class Options
{
private static bool _updateParts;

public Options(bool updateParts, bool doNotUpdateParts)
{
_updateParts = updateParts;
if (doNotUpdateParts) _updateParts = false;
}

[Option('c', "updateParts", SetName = "update", Required = true, Default = true)]
public static bool UpdateParts { get { return _updateParts; } }

[Option('C', "no-updateParts", SetName = "noUpdate", Required = true, Default = false)]
public static bool DoNotUpdateParts { get { return !_updateParts; } }
}`

Generally speaking this works, but it means I can't add two other options which are mutually exclusive. Imagine I now want to add:

- --doLogging
- --not-doLogging

I can't make them mutually exclusive because they don't belong to either set update or noUpdate.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。