Skip to content

Commit 4fad27b

Browse files
committed
ConsoleHelpAsException could be called from runner
1 parent 6889755 commit 4fad27b

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

ManyConsole.CommandLineUtils/ConsoleCommand.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,42 @@ internal void Register(CommandLineApplication app)
4141
remainingArgs =c.Argument("", RemainingArgumentsHelpText, multipleValues: (RemainingArgumentsCount ?? 100) > 1);
4242
}
4343
c.OnExecute(() => {
44-
if(TraceCommandAfterParse){
45-
string introLine = String.Format("Executing {0}", Command);
44+
45+
try{
46+
if(TraceCommandAfterParse){
47+
string introLine = String.Format("Executing {0}", Command);
4648

47-
if ((OneLineDescription?.Length ?? 0) == 0){
48-
introLine += String.Format(" ({0})",OneLineDescription);
49-
}
49+
if ((OneLineDescription?.Length ?? 0) == 0){
50+
introLine += String.Format(" ({0})",OneLineDescription);
51+
}
5052

51-
c.Out.WriteLine(introLine);
53+
c.Out.WriteLine(introLine);
5254

53-
}
54-
foreach (var option in OptionsHasd)
55-
{
56-
option.Invoke();
57-
}
55+
}
56+
foreach (var option in OptionsHasd)
57+
{
58+
option.Invoke();
59+
}
5860

59-
try{
6061
CheckRequiredArguments();
62+
63+
if(RemainingArgumentsCount != 0){
64+
var actCount =(remainingArgs?.Values.Count() ?? 0);
65+
if(actCount < RemainingArgumentsCount){
66+
c.Out.WriteLine("Invalid number of arguments-- expected {1} more.", RemainingArgumentsCount - actCount);
67+
c.ShowHelp();
68+
return 2;
69+
}
70+
}
71+
72+
return Run(remainingArgs?.Values.ToArray() ?? new string []{});
73+
6174
}catch(ConsoleHelpAsException ex){
6275
c.Out.WriteLine(ex.Message);
6376
c.ShowHelp();
6477
return 2;
6578
}
6679

67-
if(RemainingArgumentsCount != 0){
68-
var actCount =(remainingArgs?.Values.Count() ?? 0);
69-
if(actCount < RemainingArgumentsCount){
70-
c.Out.WriteLine("Invalid number of arguments-- expected {1} more.", RemainingArgumentsCount - actCount);
71-
c.ShowHelp();
72-
return 2;
73-
}
74-
}
75-
76-
return Run(remainingArgs?.Values.ToArray() ?? new string []{});
7780
});
7881
});
7982
}

ManyConsole.CommandLineUtils/ManyConsole.CommandLineUtils.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1616
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1717
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
18-
<Version>1.1.4-alpha</Version>
18+
<Version>1.1.5-alpha</Version>
1919
</PropertyGroup>
2020

2121
<ItemGroup>

0 commit comments

Comments
 (0)