Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit e561b96

Browse files
Add fsi file
1 parent b6e8f73 commit e561b96

File tree

3 files changed

+90
-84
lines changed

3 files changed

+90
-84
lines changed

src/Fargo/Fargo.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open Console
1010

1111
[<AutoOpen>]
1212
module Core =
13-
type Completer = string -> string list
13+
type Completer = string -> Token list -> string list
1414

1515
[<Flags>]
1616
type UsageType =
@@ -492,9 +492,9 @@ module Operators =
492492
let (|>>) x v = x |> map (fun _ -> v)
493493

494494
module Completer =
495-
let empty (s: string) : string list = []
495+
let empty (s: string) (_: Tokens) : string list = []
496496

497-
let choices (choices: string list) (s: string) _ =
497+
let choices (choices: string list) (s: string) (_: Tokens) =
498498
[ for c in choices do
499499
if c.StartsWith(s) then
500500
c

src/Fargo/Fargo.fsi

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,122 @@
1-
module Fargo
1+
namespace Fargo
22

33
open System
44

5-
type Quotes =
6-
| NoQuotes
7-
| Quotes of char
8-
| StartQuote of char
5+
[<AutoOpen>]
6+
module Core =
7+
type Completer = string -> Token list -> string list
98

10-
type Token =
11-
{ Text: string
12-
Start: int
13-
End: int
14-
Quotes: Quotes }
9+
[<Flags>]
10+
type UsageType =
11+
| None = 0
12+
| Arg = 1
13+
| Required = 2
14+
| Many = 4
1515

16-
module Token =
17-
/// converts a command line string to a list of tokens
18-
val ofString: string -> Token list
19-
/// converts a list of command line strings to a list of tokens
20-
val ofList: string list -> Token list
21-
/// convert the command line supplied to tokens
22-
val ofCmdLine: string seq -> Token list
23-
/// converts a token list to a string (keeping original position)
24-
val toString: Token list -> string
16+
type Usage = { Name: string option; Alt: string option; Value: string option; Description: string; Help: string option; Type: UsageType}
17+
with
18+
member IsRequired : bool
19+
member IsArg: bool
20+
member IsMany: bool
2521

22+
type Usages =
23+
{ Path: Usage list
24+
Options: Usage list }
25+
type Tokens = Token list
2626

27-
type Usage = { Name: string; Alt: string option; Description: string}
28-
type Usages = Usage list
29-
type CommandLine = Token list
30-
type Completer = string -> string list
27+
type ParseResult<'t> = Result<'t, string list>
3128

32-
type ParseResult<'t> =
33-
| Success of 't
34-
| Failure of string list
35-
| Complete of string list * important: bool
29+
type Parse<'a> = Tokens -> ParseResult<'a> * Tokens * Usages
30+
type Complete = int -> Tokens -> string list * bool
31+
type Arg<'a> =
32+
{ Parse: Parse<'a>
33+
Complete: Complete }
3634

37-
type Arg<'a> = int voption -> CommandLine -> ParseResult<'a> * CommandLine * Usages
35+
module Usages =
36+
val merge : Usages -> Usages -> Usages
37+
38+
val empty: Usages
3839

3940
module Usage =
4041
val isMatch: Usage -> Token -> bool
41-
val isStop: int voption -> Token -> bool
42+
val isStop: int -> Token -> bool
4243

43-
val (|IsPrefix|_|): int voption -> Token -> unit option
44+
val (|IsPrefix|_|): int -> Token -> unit option
45+
46+
val complete: Usage -> string -> string list * bool
47+
4448

45-
val complete: Usage -> string -> ParseResult<'t>
4649

47-
val change: (string -> string) -> Usage list -> Usage list
4850

49-
module Alt =
50-
val ofString: name:string -> string option
51+
[<AutoOpen>]
52+
module Fargo =
53+
/// parse the command line arguments with the specifier arg parser and pass
54+
/// parsed result to the suppied function
55+
val cmd: name:string -> alt:string -> description:string -> Arg<string>
56+
val optc: name:string -> alt:string -> value: string -> description:string -> completer: Completer -> Arg<string option>
57+
val opt: name:string -> alt:string -> value:string -> description:string -> Arg<string option>
5158

59+
val reqOpt: arg:Arg<'a option> -> Arg<'a>
5260

53-
/// parse the command line arguments with the specifier arg parser and pass
54-
/// parsed result to the suppied function
55-
val cmd: name:string -> alt:string -> description:string -> Arg<string>
56-
val arg: name:string -> alt:string -> description:string -> Arg<string option>
57-
val completer: Completer -> Arg<string option> -> Arg<string option>
61+
val argc: value: string -> description:string -> completer: Completer -> Arg<string option>
62+
val arg: value: string -> description:string -> Arg<string option>
5863

59-
val reqArg: Arg<'a option> -> Arg<'a>
60-
val flag: string -> string -> string -> Arg<bool>
64+
val reqArg: Arg<'a option> -> Arg<'a>
65+
val flag: string -> string -> string -> Arg<bool>
6166

62-
val reqFlag: Arg<bool> -> Arg<bool>
67+
val reqFlag: Arg<bool> -> Arg<bool>
6368

64-
val parse: ('a -> Result<'b, string>) -> Arg<'a> -> Arg<'b>
65-
val optParse: ('a -> Result<'b, string>) -> Arg<'a option> -> Arg<'b option>
66-
val listParse: ('a -> Result<'b, string>) -> Arg<'a list> -> Arg<'b list>
69+
val parse: ('a -> Result<'b, string>) -> Arg<'a> -> Arg<'b>
70+
val optParse: ('a -> Result<'b, string>) -> Arg<'a option> -> Arg<'b option>
71+
val listParse: ('a -> Result<'b, string>) -> Arg<'a list> -> Arg<'b list>
6772

68-
val nonEmpty: string -> Arg<'a list> -> Arg<'a list>
73+
val nonEmpty: string -> Arg<'a list> -> Arg<'a list>
6974

70-
val map: ('a -> 'b) -> Arg<'a> -> Arg<'b>
71-
val optMap: ('a -> 'b) -> Arg<'a option> -> Arg<'b option>
72-
val defaultValue: 'a -> Arg<'a option> -> Arg<'a>
73-
val map2: ('a -> 'b -> 'c) -> Arg<'a> -> Arg<'b> -> Arg<'c>
74-
val bind: ('a -> Arg<'b>) -> Arg<'a> -> Arg<'b>
75-
val ret: 'a -> Arg<'a>
75+
val map: ('a -> 'b) -> Arg<'a> -> Arg<'b>
76+
val optMap: ('a -> 'b) -> Arg<'a option> -> Arg<'b option>
77+
val defaultValue: 'a -> Arg<'a option> -> Arg<'a>
78+
val map2: ('a -> 'b -> 'c) -> Arg<'a> -> Arg<'b> -> Arg<'c>
79+
val bind: ('a -> Arg<'b>) -> Arg<'a> -> Arg<'b>
80+
val ret: 'a -> Arg<'a>
7681

77-
[<Class>]
78-
type CmdLineBuilder =
79-
member Bind: Arg<'a> * ('a -> Arg<'b>) -> Arg<'b>
80-
member BindReturn: Arg<'a> * ('a -> 'b) -> Arg<'b>
81-
member MergeSources: Arg<'a> * Arg<'b> -> Arg<'a * 'b>
82-
member Return: 'a -> Arg<'a>
83-
member ReturnFrom: Arg<'a> -> Arg<'a>
84-
member Zero: unit -> Arg<unit>
82+
[<Class>]
83+
type FargoBuilder =
84+
member Bind: Arg<'a> * ('a -> Arg<'b>) -> Arg<'b>
85+
member BindReturn: Arg<'a> * ('a -> 'b) -> Arg<'b>
86+
member MergeSources: Arg<'a> * Arg<'b> -> Arg<'a * 'b>
87+
member Return: 'a -> Arg<'a>
88+
member ReturnFrom: Arg<'a> -> Arg<'a>
89+
member Zero: unit -> Arg<unit>
8590

86-
val cmdLine: CmdLineBuilder
91+
val fargo: FargoBuilder
8792

88-
val alt: Arg<'a> -> Arg<'a> -> Arg<'a>
89-
val optAlt: Arg<'a option> -> Arg<'a option> -> Arg<'a option>
90-
val error: message:string -> Arg<'a>
91-
val errorf<'a> : messageFunc:(Token list -> string) -> Arg<'a>
93+
val alt: Arg<'a> -> Arg<'a> -> Arg<'a>
94+
val optAlt: Arg<'a option> -> Arg<'a option> -> Arg<'a option>
95+
val error: message:string -> Arg<'a>
96+
val errorf<'a> : messageFunc:(Token list -> string) -> Arg<'a>
9297

93-
val cmdError<'a> : Arg<'a>
98+
val cmdError<'a> : Arg<'a>
9499

95-
module Int32 =
96-
val tryParse: error:string -> input:string -> Result<int, string>
97-
module DateTime =
98-
val tryParse: error:string -> input:string -> Result<DateTime, string>
100+
val help: text:string -> arg: Arg<'t> -> Arg<'t>
99101

102+
module Operators =
103+
val (<|>) : Arg<'a> -> Arg<'a> -> Arg<'a>
104+
val (<|?>) : Arg<'a option> -> Arg<'a option> -> Arg<'a option>
105+
val (|>>) : Arg<'a> -> 'b -> Arg<'b>
100106

101-
val tryParse: Arg<'a> -> Token list -> Result<'a, string list * Usage list>
102-
val complete: Arg<'a> -> int -> Token list -> string list
103107

108+
[<AutoOpen>]
109+
module Run =
110+
val tryParseTokens: arg:Arg<'a> -> tokens:Tokens -> Result<'a, string list * Usages>
111+
val complete: Arg<'a> -> int -> Tokens -> string list
104112

105-
val printUsage: Usage list -> unit
106113

107-
/// parse the command line arguments with the specifier arg parser and pass
108-
/// parsed result to the suppied function
109-
val run: appName:string -> arg:Arg<'a> -> cmdLine:string[] -> ('a -> unit) -> int
114+
val printUsage: Usages -> unit
115+
val printHelp: Usages -> unit
116+
117+
/// parse the command line arguments with the specifier arg parser and pass
118+
/// parsed result to the suppied function
119+
val run: appName:string -> arg:Arg<'a> -> cmdLine:string[] -> f:(Threading.CancellationToken -> 'a -> Threading.Tasks.Task<int>) -> int
110120

111121
module Completer =
112122
/// an empty completer than returns no suggestions
@@ -115,11 +125,6 @@ module Completer =
115125
// a completer that returns suggestions from specified list
116126
val choices: choices:string list -> Completer
117127

118-
module Opertators =
119-
val (<|>): Arg<'a> -> Arg<'a> -> Arg<'a>
120-
val (<|?>): Arg<'a option> -> Arg<'a option> -> Arg<'a option>
121-
val (|>>): Arg<'a> -> 'b -> Arg<'b>
122-
123128
module Pipe =
124129
/// reads argument value from standard input
125130
val stdIn : Arg<string list>

src/Fargo/Fargo.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Compile Include="Console.fs" />
99
<Compile Include="Token.fs" />
1010
<Compile Include="Parsers.fs" />
11+
<Compile Include="Fargo.fsi" />
1112
<Compile Include="Fargo.fs" />
1213
</ItemGroup>
1314
<Import Project="..\..\.paket\Paket.Restore.targets" />

0 commit comments

Comments
 (0)