From 6a1389bbe1dff71bba033f88c3c0eb039895efcf Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Wed, 29 Jun 2016 13:39:02 +0300 Subject: [PATCH] implement ExactlyOnceAttribute --- src/Argu/PreCompute.fs | 5 +++-- src/Argu/Types.fs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Argu/PreCompute.fs b/src/Argu/PreCompute.fs index b0f033c2..42e1a2ec 100644 --- a/src/Argu/PreCompute.fs +++ b/src/Argu/PreCompute.fs @@ -139,8 +139,9 @@ let rec private preComputeUnionCaseArgInfo (stack : Type list) (helpParam : Help let isFirst = uci.ContainsAttribute () let isAppSettingsCSV = uci.ContainsAttribute () - let isMandatory = uci.ContainsAttribute (true) - let isUnique = uci.ContainsAttribute (true) + let isExactlyOnce = uci.ContainsAttribute(true) + let isMandatory = isExactlyOnce || uci.ContainsAttribute (true) + let isUnique = isExactlyOnce || uci.ContainsAttribute (true) let isGatherAll = uci.ContainsAttribute () let isRest = uci.ContainsAttribute () let isHidden = uci.ContainsAttribute () diff --git a/src/Argu/Types.fs b/src/Argu/Types.fs index facf5d92..5b376fe9 100644 --- a/src/Argu/Types.fs +++ b/src/Argu/Types.fs @@ -30,6 +30,11 @@ module ArguAttributes = [] type UniqueAttribute () = inherit Attribute () + /// Demands that the argument should be specified exactly once; an exception is raised otherwise. + /// Equivalent to attaching both the Mandatory and Unique attribute on the parameter. + [] + type ExactlyOnceAttribute () = inherit Attribute () + /// Gathers all parsed results from both AppSettings and command line. [] type GatherAllSourcesAttribute () = inherit Attribute ()