This commit is contained in:
Smaug123
2025-04-17 18:45:57 +01:00
parent 01714aeba0
commit 75ce8c1f64
3 changed files with 179 additions and 54 deletions

View File

@@ -64,8 +64,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -256,8 +261,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -448,8 +458,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -684,8 +699,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1062,8 +1082,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1398,8 +1423,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1591,8 +1621,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1723,8 +1758,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1877,8 +1917,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -1995,8 +2040,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2154,8 +2204,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2268,8 +2323,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2364,8 +2424,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2476,8 +2541,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2625,8 +2695,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2750,8 +2825,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -2886,8 +2966,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3102,8 +3187,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3220,8 +3310,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3348,8 +3443,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3470,8 +3570,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3602,8 +3707,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else
@@ -3718,8 +3828,13 @@ module internal ArgParseHelpers_ConsumePlugin =
outOfPlacePositionals
|> String.concat " "
|> (fun x ->
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. "
+ x
if 0 = outOfPlacePositionals.Count then
"Unmatched args which look like they are meant to be flags. " + x
else
sprintf
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
positionalConsumers.[0]
x
)
|> errors.Add
else

View File

@@ -80,7 +80,7 @@ module TestArgParser =
exc.Message
|> shouldEqual
"""Errors during parse!
Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. --non-existent"""
Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--rest=` syntax, or place them after a trailing `--`. --non-existent"""
[<Test>]
let ``Can supply positional args with key`` () =
@@ -692,7 +692,7 @@ Required argument '--turn-it-on' received no value"""
exc.Message
|> shouldEqual
"""Errors during parse!
Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. --b=false --c"""
Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--dont-grab-everything=` syntax, or place them after a trailing `--`. --b=false --c"""
let exc =
Assert.Throws<exn> (fun () ->

View File

@@ -1234,12 +1234,22 @@ module internal ShibaGenerator =
|> SynExpr.pipeThroughFunction (
SynExpr.createLambda
"x"
(SynExpr.plus
// TODO: if we have a positional consumer, point this out, but otherwise don't
// TODO: print the help text here
(SynExpr.CreateConst
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `--my-arg-name=` syntax, or place them after a trailing `--`. ")
(SynExpr.createIdent "x"))
(SynExpr.ifThenElse
(SynExpr.equals
(SynExpr.CreateConst 0)
(SynExpr.dotGet "Count" (SynExpr.createIdent "outOfPlacePositionals")))
((SynExpr.createIdent "sprintf")
|> SynExpr.applyTo (
SynExpr.CreateConst
"Unmatched args which look like they are meant to be flags. If you intended them as positional args, explicitly pass them with the `%s=` syntax, or place them after a trailing `--`. %s"
)
|> SynExpr.applyTo (
SynExpr.index (SynExpr.CreateConst 0) (SynExpr.createIdent "positionalConsumers")
)
|> SynExpr.applyTo (SynExpr.createIdent "x"))
(SynExpr.plus
(SynExpr.CreateConst "Unmatched args which look like they are meant to be flags. ")
(SynExpr.createIdent "x")))
)
|> SynExpr.pipeThroughFunction (SynExpr.createLongIdent [ "errors" ; "Add" ])
|> SynExpr.ifThenElse