Skip to content

Commit

Permalink
Merge pull request #188 from bartelink/w5
Browse files Browse the repository at this point in the history
chore: Up to warning level 5
  • Loading branch information
nojaf authored Dec 12, 2023
2 parents c240943 + d3867c3 commit 8b28c9e
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 297 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsPackable>false</IsPackable>
<WarningLevel>5</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion docs/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Args =
| Detach
with
interface IArgParserTemplate with
member __.Usage = ""
member _.Usage = ""

(**
Expand Down
2 changes: 1 addition & 1 deletion docs/perf.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Arguments =
| Argument
with
interface IArgParserTemplate with
member __.Usage =
member _.Usage =
"Usage"

type FactAttribute () = inherit System.Attribute()
Expand Down
3 changes: 1 addition & 2 deletions samples/Argu.Samples.LS/Arguments.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type LsArguments =
| [<AltCommandLine("-Z")>] Context
| [<CustomCommandLine("-1")>] List_One
| Version
with
interface IArgParserTemplate with
member arg.Usage =
match arg with
Expand All @@ -84,7 +83,7 @@ with
| Ignore_Backups -> "do not list implied entries ending with ~"
| Color _ -> "colorize the output; WHEN can be 'always' (default\nif omitted), 'auto', or 'never'"
| Directory -> "list directories themselves, not their contents"
| Dired _ -> "generate output designed for Emacs' dired mode"
| Dired -> "generate output designed for Emacs' dired mode"
| F -> "do not sort, enable -aU, disable -ls --color"
| Format _ -> "append indicator (one of */=>@|) to entries"
| Group_Directories_First -> "group directories before files;\ncan be augmented with a --sort option, but any\nuse of --sort=none (-U) disables grouping"
Expand Down
56 changes: 28 additions & 28 deletions src/Argu/ArgumentParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, hel
if _usageStringCharacterWidth < 1 then invalidArg "usageStringCharacterWidth" "Must be positive value."

/// Gets the help flags specified for the CLI parser
member __.HelpFlags = argInfo.HelpParam.Flags
member _.HelpFlags = argInfo.HelpParam.Flags
/// Gets the help description specified for the CLI parser
member __.HelpDescription = argInfo.HelpParam.Description
member _.HelpDescription = argInfo.HelpParam.Description
/// Gets the message that will be displayed at the top of the help text
member __.HelpTextMessage = helpTextMessage
member _.HelpTextMessage = helpTextMessage
/// Returns true if parser corresponds to a subcommand
member __.IsSubCommandParser = argInfo.TryGetParent() |> Option.isSome
member _.IsSubCommandParser = argInfo.TryGetParent() |> Option.isSome
/// If subcommand parser, gets parent argument metadata
member __.ParentInfo = argInfo.TryGetParent() |> Option.map (fun p -> p.ToArgumentCaseInfo())
member _.ParentInfo = argInfo.TryGetParent() |> Option.map (fun p -> p.ToArgumentCaseInfo())
/// Gets the default error handler used by the instance
member __.ErrorHandler = errorHandler
member _.ErrorHandler = errorHandler

/// Gets metadata for all union cases used by parser
member __.GetArgumentCases() =
member _.GetArgumentCases() =
argInfo.Cases.Value
|> Seq.map (fun p -> p.ToArgumentCaseInfo())
|> Seq.toList

/// Gets all subcommand parsers for given parser
member __.GetSubCommandParsers() =
member _.GetSubCommandParsers() =
argInfo.Cases.Value
|> Seq.choose (fun cs -> match cs.ParameterInfo.Value with SubCommand(e,nu,_) -> Some(e,nu) | _ -> None)
|> Seq.map (fun (e,nu) ->
e.Accept {
new ITemplateFunc<ArgumentParser> with
member __.Invoke<'Template when 'Template :> IArgParserTemplate> () =
member _.Invoke<'Template when 'Template :> IArgParserTemplate> () =
new ArgumentParser<'Template>(nu, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) :> _
})
|> Seq.toList
Expand All @@ -49,7 +49,7 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, hel
/// <param name="programName">Override the default program name settings.</param>
/// <param name="hideSyntax">Do not display 'USAGE: [syntax]' at top of usage string. Defaults to false.</param>
/// <param name="usageStringCharacterWidth">Text width used when formatting the usage string.</param>
member __.PrintUsage (?message : string, ?programName : string, ?hideSyntax : bool, ?usageStringCharacterWidth : int) : string =
member _.PrintUsage (?message : string, ?programName : string, ?hideSyntax : bool, ?usageStringCharacterWidth : int) : string =
let programName = defaultArg programName _programName
let hideSyntax = defaultArg hideSyntax false
let usageStringCharacterWidth = defaultArg usageStringCharacterWidth _usageStringCharacterWidth
Expand All @@ -60,7 +60,7 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, hel
/// </summary>
/// <param name="programName">Program name identifier placed at start of syntax string</param>
/// <param name="usageStringCharacterWidth">Text width used when formatting the usage string.</param>
member __.PrintCommandLineSyntax (?programName : string, ?usageStringCharacterWidth : int) : string =
member _.PrintCommandLineSyntax (?programName : string, ?usageStringCharacterWidth : int) : string =
let programName = defaultArg programName _programName
let usageStringCharacterWidth = defaultArg usageStringCharacterWidth _usageStringCharacterWidth
mkCommandLineSyntax argInfo "" usageStringCharacterWidth programName |> StringExpr.build
Expand Down Expand Up @@ -107,7 +107,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
new (?programName : string, ?helpTextMessage : string, ?usageStringCharacterWidth : int, ?errorHandler : IExiter, ?checkStructure: bool) =
let usageStringCharacterWidth = match usageStringCharacterWidth with None -> getDefaultCharacterWidth() | Some w -> w
let programName = match programName with Some pn -> pn | None -> currentProgramName.Value
let errorHandler = match errorHandler with Some e -> e | None -> new ExceptionExiter() :> _
let errorHandler = match errorHandler with Some e -> e | None -> ExceptionExiter() :> _

let argInfo =
match checkStructure with
Expand All @@ -124,7 +124,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
/// <param name="ignoreUnrecognized">Ignore CLI arguments that do not match the schema. Defaults to false.</param>
/// <param name="raiseOnUsage">Treat '--help' parameters as parse errors. Defaults to true.</param>
member __.ParseCommandLine (?inputs : string [], ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> =
member _.ParseCommandLine (?inputs : string [], ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> =
let ignoreMissing = defaultArg ignoreMissing false
let ignoreUnrecognized = defaultArg ignoreUnrecognized false
let raiseOnUsage = defaultArg raiseOnUsage true
Expand All @@ -142,7 +142,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <summary>Parse arguments using specified configuration reader only. This defaults to the AppSettings configuration of the current process.</summary>
/// <param name="configurationReader">Configuration reader used to source the arguments. Defaults to the AppSettings configuration of the current process.</param>
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
member __.ParseConfiguration (configurationReader : IConfigurationReader, ?ignoreMissing : bool) : ParseResults<'Template> =
member _.ParseConfiguration (configurationReader : IConfigurationReader, ?ignoreMissing : bool) : ParseResults<'Template> =
let ignoreMissing = defaultArg ignoreMissing false

try
Expand All @@ -160,7 +160,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
/// <param name="ignoreUnrecognized">Ignore CLI arguments that do not match the schema. Defaults to false.</param>
/// <param name="raiseOnUsage">Treat '--help' parameters as parse errors. Defaults to true.</param>
member __.Parse (?inputs : string [], ?configurationReader : IConfigurationReader, ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> =
member _.Parse (?inputs : string [], ?configurationReader : IConfigurationReader, ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> =
let ignoreMissing = defaultArg ignoreMissing false
let ignoreUnrecognized = defaultArg ignoreUnrecognized false
let raiseOnUsage = defaultArg raiseOnUsage true
Expand All @@ -183,16 +183,16 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// Converts a sequence of template argument inputs into a ParseResults instance
/// </summary>
/// <param name="inputs">Argument input sequence.</param>
member __.ToParseResults (inputs : seq<'Template>) : ParseResults<'Template> =
member _.ToParseResults (inputs : seq<'Template>) : ParseResults<'Template> =
mkParseResultFromValues argInfo errorHandler _usageStringCharacterWidth _programName helpTextMessage inputs

/// <summary>
/// Gets a subparser associated with specific subcommand instance
/// </summary>
/// <param name="expr">Expression providing the subcommand union constructor.</param>
member __.GetSubCommandParser ([<ReflectedDefinition>] expr : Expr<ParseResults<'SubTemplate> -> 'Template>) : ArgumentParser<'SubTemplate> =
member _.GetSubCommandParser ([<ReflectedDefinition>] expr : Expr<ParseResults<'SubTemplate> -> 'Template>) : ArgumentParser<'SubTemplate> =
let uci = expr2Uci expr
let case = argInfo.Cases.Value.[uci.Tag]
let case = argInfo.Cases.Value[uci.Tag]
match case.ParameterInfo.Value with
| SubCommand (_,nestedUnion,_) ->
new ArgumentParser<'SubTemplate>(nestedUnion, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler)
Expand All @@ -202,40 +202,40 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// Gets the F# union tag representation for given argument
/// </summary>
/// <param name="value">Argument instance.</param>
member __.GetTag(value : 'Template) : int =
member _.GetTag(value : 'Template) : int =
argInfo.TagReader.Value (value :> obj)

/// <summary>
/// Gets argument metadata for given argument instance.
/// </summary>
/// <param name="value">Argument instance.</param>
member __.GetArgumentCaseInfo(value : 'Template) : ArgumentCaseInfo =
member _.GetArgumentCaseInfo(value : 'Template) : ArgumentCaseInfo =
let tag = argInfo.TagReader.Value (value :> obj)
argInfo.Cases.Value.[tag].ToArgumentCaseInfo()
argInfo.Cases.Value[tag].ToArgumentCaseInfo()

/// <summary>
/// Gets argument metadata for given union case constructor
/// </summary>
/// <param name="ctorExpr">Quoted union case constructor.</param>
member __.GetArgumentCaseInfo([<ReflectedDefinition>] ctorExpr : Expr<'Fields -> 'Template>) : ArgumentCaseInfo =
member _.GetArgumentCaseInfo([<ReflectedDefinition>] ctorExpr : Expr<'Fields -> 'Template>) : ArgumentCaseInfo =
let uci = expr2Uci ctorExpr
argInfo.Cases.Value.[uci.Tag].ToArgumentCaseInfo()
argInfo.Cases.Value[uci.Tag].ToArgumentCaseInfo()

/// <summary>Prints parameters in command line format. Useful for argument string generation.</summary>
member __.PrintCommandLineArguments (args : 'Template list) : string [] =
member _.PrintCommandLineArguments (args : 'Template list) : string [] =
mkCommandLineArgs argInfo (Seq.cast args) |> Seq.toArray

/// <summary>Prints parameters in command line format. Useful for argument string generation.</summary>
member __.PrintCommandLineArgumentsFlat (args : 'Template list) : string =
__.PrintCommandLineArguments args |> flattenCliTokens
member ap.PrintCommandLineArgumentsFlat (args : 'Template list) : string =
ap.PrintCommandLineArguments args |> flattenCliTokens

/// <summary>Prints parameters in App.Config format.</summary>
/// <param name="args">The parameters that fill out the XML document.</param>
/// <param name="printComments">Print XML comments over every configuration entry.</param>
member __.PrintAppSettingsArguments (args : 'Template list, ?printComments : bool) : string =
member _.PrintAppSettingsArguments (args : 'Template list, ?printComments : bool) : string =
let printComments = defaultArg printComments true
let xmlDoc = mkAppSettingsDocument argInfo printComments args
use writer = { new System.IO.StringWriter() with member __.Encoding = System.Text.Encoding.UTF8 }
use writer = { new System.IO.StringWriter() with member _.Encoding = System.Text.Encoding.UTF8 }
xmlDoc.Save writer
writer.Flush()
writer.ToString()
Expand Down
32 changes: 16 additions & 16 deletions src/Argu/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ExactlyOnceAttribute () = inherit Attribute ()
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type InheritAttribute() = inherit Attribute()

/// Denotes that the given argument should accummulate any unrecognized arguments it encounters.
/// Denotes that the given argument should accumulate any unrecognized arguments it encounters.
/// Must contain a single field of type string
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type GatherUnrecognizedAttribute() = inherit Attribute()
Expand All @@ -61,7 +61,7 @@ type NoAppSettingsAttribute () = inherit Attribute ()
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = false)>]
type HelpFlagsAttribute ([<ParamArray>] names : string []) =
inherit Attribute()
member __.Names = names
member _.Names = names

/// Specifies that Help/Usage switches should be disabled for the CLI.
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = false)>]
Expand All @@ -71,13 +71,13 @@ type DisableHelpFlagsAttribute () = inherit HelpFlagsAttribute ()
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = false)>]
type HelpDescriptionAttribute (description : string) =
inherit Attribute()
member __.Description = description
member _.Description = description

/// Declares that argument should be placed at specific position.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type CliPositionAttribute(position : CliPosition) =
inherit Attribute()
member __.Position = position
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.
Expand All @@ -101,8 +101,8 @@ type SubCommandAttribute () = inherit Attribute()
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type MainCommandAttribute (argumentName : string) =
inherit Attribute()
new () = new MainCommandAttribute(null)
member __.ArgumentName = argumentName
new () = MainCommandAttribute(null)
member _.ArgumentName = argumentName

/// Print F# 3.1 field labels in usage string. OBSOLETE
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Property, AllowMultiple = false)>]
Expand All @@ -116,7 +116,7 @@ type PrintLabelsAttribute () = inherit Attribute ()
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type CustomAssignmentAttribute (separator : string) =
inherit Attribute ()
member __.Separator = separator
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.
Expand All @@ -138,7 +138,7 @@ type ColonAssignmentAttribute () =
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type CustomAssignmentOrSpacedAttribute (separator : string) =
inherit Attribute ()
member __.Separator = separator
member _.Separator = separator

/// Use '--param=arg' assignment syntax in CLI.
/// Parameters can also be assigned using space as separator e.g. '--param arg'
Expand All @@ -159,36 +159,36 @@ type ColonAssignmentOrSpacedAttribute () =
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type CustomCommandLineAttribute (name : string, [<ParamArray>]altNames : string []) =
inherit Attribute ()
member __.Name = name
member __.AltNames = altNames
member _.Name = name
member _.AltNames = altNames

/// 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.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = true)>]
type AltCommandLineAttribute ([<ParamArray>] names : string []) =
inherit Attribute ()
member __.Names = names
member _.Names = names

/// Declares a custom key identifier for the current parameter in AppSettings parsing.
/// Replaces the auto-generated identifier name.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
type CustomAppSettingsAttribute (name : string) =
inherit Attribute ()
member __.Name = name
member _.Name = name

/// Specify a custom value separator in AppSettings parsing parameters.
/// Used in CSV or list-based parameter parsing.
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Property, AllowMultiple = false)>]
type AppSettingsSeparatorAttribute ([<ParamArray>] separators : string [], splitOptions : StringSplitOptions) =
inherit Attribute()
new (separator : char) = new AppSettingsSeparatorAttribute([|string separator|], StringSplitOptions.None)
member __.Separators = separators
member __.SplitOptions = splitOptions
new (separator : char) = AppSettingsSeparatorAttribute([|string separator|], StringSplitOptions.None)
member _.Separators = separators
member _.SplitOptions = splitOptions

/// Specifies a custom prefix for auto-generated CLI names.
/// This defaults to double dash ('--').
[<AttributeUsage(AttributeTargets.Property ||| AttributeTargets.Class, AllowMultiple = false)>]
type CliPrefixAttribute(prefix : string) =
inherit Attribute()
member __.Prefix = prefix
member _.Prefix = prefix
Loading

0 comments on commit 8b28c9e

Please sign in to comment.