From ea16d85f0f7fe8b97ab1f24241423fa56c8c6837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lidstr=C3=B6m?= Date: Fri, 17 May 2024 17:06:26 +0200 Subject: [PATCH] fixes #242: add missing attribute targets (#243) * fixes #242: add missing attribute targets * update release notes --- RELEASE_NOTES.md | 7 ++-- src/Argu/Attributes.fs | 80 +++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1f034c9b..2ea2dae1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +### 6.2.4 +* Add `AttributeUsage` targets for methods which will be required in .NET 8.0.300 [#243](https://github.com/fsprojects/Argu/pull/243) [@dlidstrom](https://github.com/dlidstrom) + ### 6.2.3 * Improve error message on missing cases on a subcommands (display all missing cases) [#236](https://github.com/fsprojects/Argu/pull/236) [@fpellet](https://github.com/fpellet) * Fix the regression of the [#127](https://github.com/fsprojects/Argu/pull/127) merged in 6.1.2 and fix usage display when there are missing case in subcommands. [#236](https://github.com/fsprojects/Argu/pull/236) [@fpellet](https://github.com/fpellet) @@ -24,7 +27,7 @@ * Use [`Dotnet.ReproducibleBuilds`](https://github.com/dotnet/reproducible-builds) [#174](https://github.com/fsprojects/Argu/pull/174) ### 6.1.2 -* Fix Mandatory arguments in nested subcommands. [#116](https://github.com/fsprojects/Argu/issues/116) [@chestercodes](https://github.com/chestercodes) +* Fix Mandatory arguments in nested subcommands. [#116](https://github.com/fsprojects/Argu/issues/116) [@chestercodes](https://github.com/chestercodes) * Fix Consistent handling of numeric decimal separators using invariant culture. [#159](https://github.com/fsprojects/Argu/issues/159) [@stmax82](https://github.com/stmax82) ### 6.1.1 @@ -194,5 +197,5 @@ * Fix packaging issue. #### 0.5.8 -* Include optional BindingFlags parameter. +* Include optional BindingFlags parameter. * Include support for all primitive types. diff --git a/src/Argu/Attributes.fs b/src/Argu/Attributes.fs index f53d39b7..d3bd98da 100644 --- a/src/Argu/Attributes.fs +++ b/src/Argu/Attributes.fs @@ -6,38 +6,38 @@ open System /// Parse multiple parameters in AppSettings as comma separated values. OBSOLETE [] -[] +[] type ParseCSVAttribute () = inherit Attribute () /// Consume all remaining CLI tokens using this parameter wherever it might occur. OBSOLETE [] -[] +[] type RestAttribute () = inherit Attribute () /// Hides argument from command line argument usage string. -[] +[] type HiddenAttribute () = inherit Attribute () /// Demands at least one parsed result for this argument; a parse exception is raised otherwise. -[] +[] type MandatoryAttribute () = inherit Attribute () /// Demands that the argument should be specified at most once; a parse exception is raised otherwise. -[] +[] type UniqueAttribute () = inherit Attribute () /// Demands that the argument should be specified exactly once; a parse exception is raised otherwise. /// Equivalent to attaching both the Mandatory and Unique attribute on the parameter. -[] +[] type ExactlyOnceAttribute () = inherit Attribute () /// Denotes that the given argument should be inherited in the scope of any subcommands. -[] +[] type InheritAttribute() = inherit Attribute() /// Denotes that the given argument should accumulate any unrecognized arguments it encounters. /// Must contain a single field of type string -[] +[] type GatherUnrecognizedAttribute() = inherit Attribute() /// Demands that at least one subcommand is specified in the CLI; a parse exception is raised otherwise. @@ -46,20 +46,20 @@ type RequireSubcommandAttribute () = inherit Attribute() /// Requires that CLI parameters should not override AppSettings parameters. /// Will return parsed results from both AppSettings and CLI. -[] +[] type GatherAllSourcesAttribute () = inherit Attribute () /// Disable CLI parsing for this argument. Use for AppSettings parsing only. -[] +[] type NoCommandLineAttribute () = inherit Attribute () /// Disable AppSettings parsing for this branch. Use for CLI parsing only. -[] +[] type NoAppSettingsAttribute () = inherit Attribute () /// Specifies a custom set of Help/Usage switches for the CLI. [] -type HelpFlagsAttribute ([] names : string []) = +type HelpFlagsAttribute ([] names : string []) = inherit Attribute() member _.Names = names @@ -74,38 +74,38 @@ type HelpDescriptionAttribute (description : string) = member _.Description = description /// Declares that argument should be placed at specific position. -[] +[] type CliPositionAttribute(position : CliPosition) = inherit Attribute() member _.Position = position /// Declares that argument can only be placed at the beginning of the CLI syntax. /// A parse exception will be raised if that is not the case. -[] +[] type FirstAttribute () = inherit CliPositionAttribute (CliPosition.First) /// Declares that argument can only be placed at the end of the CLI syntax. /// A parse exception will be raised if that is not the case. -[] +[] type LastAttribute () = inherit CliPositionAttribute (CliPosition.Last) /// Declares that argument is a subcommand. /// A parse exception will be raised if the argument has parameters /// and their type is not ParseResults<_>. /// Implicit if the argument does have a parameter of type ParseResults<_>. -[] +[] type SubCommandAttribute () = inherit Attribute() /// Declares that argument is the main command of the CLI syntax. /// Arguments are specified without requiring a switch. -[] -type MainCommandAttribute (argumentName : string) = +[] +type MainCommandAttribute (argumentName : string) = inherit Attribute() new () = MainCommandAttribute(null) member _.ArgumentName = argumentName /// Print F# 3.1 field labels in usage string. OBSOLETE -[] +[] [] type PrintLabelsAttribute () = inherit Attribute () @@ -113,29 +113,29 @@ type PrintLabelsAttribute () = inherit Attribute () /// e.g. '--paramarg' or '--param keyvalue'. /// Requires that the argument should have parameters of arity 1 or 2 only. /// Can be used to specify any assignment separator. -[] -type CustomAssignmentAttribute (separator : string) = +[] +type CustomAssignmentAttribute (separator : string) = inherit Attribute () member _.Separator = separator /// Use '--param=arg' or '--param key=value' assignment syntax in CLI. /// Requires that the argument should have parameters of arity 1 or 2 only. -[] -type EqualsAssignmentAttribute () = +[] +type EqualsAssignmentAttribute () = inherit CustomAssignmentAttribute("=") /// Use '--param:arg' or '--param key:value' assignment syntax in CLI. /// Requires that the argument should have parameters of arity 1 or 2 only. -[] -type ColonAssignmentAttribute () = +[] +type ColonAssignmentAttribute () = inherit CustomAssignmentAttribute(":") - + /// Use a custom separator for parameter assignment. /// e.g. '--paramarg' /// Parameters can also be assigned using space as separator e.g. '--param arg' /// Requires that the argument should have parameters of arity 1 only. /// Can be used to specify any assignment separator. -[] +[] type CustomAssignmentOrSpacedAttribute (separator : string) = inherit Attribute () member _.Separator = separator @@ -143,20 +143,20 @@ type CustomAssignmentOrSpacedAttribute (separator : string) = /// Use '--param=arg' assignment syntax in CLI. /// Parameters can also be assigned using space as separator e.g. '--param arg' /// Requires that the argument should have parameters of arity 1 only. -[] -type EqualsAssignmentOrSpacedAttribute () = +[] +type EqualsAssignmentOrSpacedAttribute () = inherit CustomAssignmentOrSpacedAttribute("=") /// Use '--param:arg' assignment syntax in CLI. /// Parameters can also be assigned using space as separator e.g. '--param arg' /// Requires that the argument should have parameters of arity 1 only. -[] -type ColonAssignmentOrSpacedAttribute () = +[] +type ColonAssignmentOrSpacedAttribute () = inherit CustomAssignmentOrSpacedAttribute(":") /// Declares a custom default CLI identifier for the current parameter. /// Replaces the auto-generated identifier name. -[] +[] type CustomCommandLineAttribute (name : string, []altNames : string []) = inherit Attribute () member _.Name = name @@ -165,21 +165,21 @@ type CustomCommandLineAttribute (name : string, []altNames : string /// Declares a set of secondary CLI identifiers for the current parameter. /// Does not replace the default identifier which is either auto-generated /// or specified by the CustomCommandLine attribute. -[] -type AltCommandLineAttribute ([] names : string []) = +[] +type AltCommandLineAttribute ([] names : string []) = inherit Attribute () member _.Names = names /// Declares a custom key identifier for the current parameter in AppSettings parsing. /// Replaces the auto-generated identifier name. -[] +[] type CustomAppSettingsAttribute (name : string) = inherit Attribute () member _.Name = name /// Specify a custom value separator in AppSettings parsing parameters. /// Used in CSV or list-based parameter parsing. -[] +[] type AppSettingsSeparatorAttribute ([] separators : string [], splitOptions : StringSplitOptions) = inherit Attribute() new (separator : char) = AppSettingsSeparatorAttribute([|string separator|], StringSplitOptions.None) @@ -188,7 +188,7 @@ type AppSettingsSeparatorAttribute ([] separators : string [], split /// Specifies a custom prefix for auto-generated CLI names. /// This defaults to double dash ('--'). -[] -type CliPrefixAttribute(prefix : string) = - inherit Attribute() - member _.Prefix = prefix \ No newline at end of file +[] +type CliPrefixAttribute(prefix : string) = + inherit Attribute() + member _.Prefix = prefix