Skip to content

Commit

Permalink
Merge pull request #45 from cloudRoutine/alt-args
Browse files Browse the repository at this point in the history
AltCommandLine can take array of alternatives
  • Loading branch information
eiriktsarpalis committed Jan 22, 2016
2 parents f2de425 + bc2cd70 commit 62f89e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/Argu/ArgInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ let preComputeArgInfo (uci : UnionCaseInfo) : ArgInfo =

let altNames =
uci.GetAttrs<AltCommandLineAttribute> ()
|> List.map (fun attr -> attr.Name)
|> List.collect (fun attr -> attr.Names|> Array.toList)


let clNames = defName :: altNames

Expand Down
5 changes: 3 additions & 2 deletions src/Argu/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ type CustomCommandLineAttribute (name : string) =

/// Sets alternative command line names.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = true)>]
type AltCommandLineAttribute (name : string) =
type AltCommandLineAttribute ([<ParamArray>] names :string []) =
inherit Attribute ()
member __.Name = name
member __.Names = names
new(name:string) = AltCommandLineAttribute([|name|])

/// Sets a custom AppSettings key name.
[<AttributeUsage(AttributeTargets.Property, AllowMultiple = false)>]
Expand Down
15 changes: 7 additions & 8 deletions tests/Argu.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open System
open System.IO

open NUnit.Framework
open FsUnit

Expand All @@ -20,8 +19,8 @@ module ``Simple Tests`` =
| [<Rest>] Rest_Arg of int
| Data of int * byte []
| Log_Level of int
| [<AltCommandLine("/D"); AltCommandLine("-D"); AltCommandLine("-z")>] Detach
| [<CustomAppSettings("Foo")>] CustomAppConfig of string * int
| [<AltCommandLine [|"/D";"-D";"-z"|] >] Detach
| [<CustomAppSettings "Foo">] CustomAppConfig of string * int
| [<EqualsAssignment>] Assignment of string
| [<First>] First_Parameter of string
with
Expand All @@ -39,7 +38,7 @@ module ``Simple Tests`` =
| CustomAppConfig _ -> "parameter with custom AppConfig key."
| First_Parameter _ -> "parameter that has to appear at beginning of command line args."

let parser = ArgumentParser.Create<Argument>("usage string")
let parser = ArgumentParser.Create<Argument> "usage string"

[<Test>]
let ``01. Simple command line parsing`` () =
Expand Down Expand Up @@ -146,15 +145,15 @@ module ``Simple Tests`` =
result.IsUsageRequested |> should equal true

type ConflictingCliNames =
| [<CustomCommandLine("foo")>] Foo of int
| [<AltCommandLine("foo")>] Bar of string
| [<CustomCommandLine "foo">] Foo of int
| [<AltCommandLine "foo">] Bar of string
with
interface IArgParserTemplate with
member a.Usage = "foo"

type ConflictinAppSettingsNames =
| [<CustomAppSettings("foo")>]Foo of int
| [<CustomAppSettings("foo")>] Bar of string
| [<CustomAppSettings "foo">]Foo of int
| [<CustomAppSettings "foo">] Bar of string
with
interface IArgParserTemplate with
member a.Usage = "foo"
Expand Down

0 comments on commit 62f89e8

Please sign in to comment.