Skip to content

Commit dc333c3

Browse files
committed
truly override help
1 parent 1083594 commit dc333c3

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

sandbox/SingleContainedApp/Program.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,25 @@ public async Task Timer([Option(0)]uint waitSeconds)
4848
}
4949
}
5050

51+
public class OverrideCheck : BatchBase
52+
{
53+
[Command(new[] { "help", "-h", "-help", "--help" }, "show help")]
54+
public void Help()
55+
{
56+
Console.WriteLine("Usage: base64urls [-version] [-help] [decode|encode|escape|unescape] [args]");
57+
Console.WriteLine("E.g., run this: base64urls decode QyMgaXMgYXdlc29tZQ==");
58+
Console.WriteLine("E.g., run this: base64urls encode \"C# is awesome.\"");
59+
Console.WriteLine("E.g., run this: base64urls escape \"This+is/goingto+escape==\"");
60+
Console.WriteLine("E.g., run this: base64urls unescape \"This-is_goingto-escape\"");
61+
}
62+
}
63+
5164
class Program
5265
{
5366
static async Task Main(string[] args)
5467
{
55-
await new HostBuilder().RunBatchEngineAsync<MyFirstBatch>(args);
68+
args = new string[] { };
69+
await new HostBuilder().RunBatchEngineAsync<OverrideCheck>(args);
5670
}
5771
}
5872
}

src/MicroBatchFramework/BatchEngineHostBuilderExtensions.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,21 @@ public static IHostBuilder UseBatchEngine<T>(this IHostBuilder hostBuilder, stri
101101
{
102102
if (defaultMethod == null || (defaultMethod.GetParameters().Length != 0 && !defaultMethod.GetParameters().All(x => x.HasDefaultValue)))
103103
{
104-
Console.WriteLine(BuildHelpParameter(method));
105-
hostBuilder.ConfigureServices(services =>
104+
if (!hasHelp)
106105
{
107-
services.AddOptions<ConsoleLifetimeOptions>().Configure(x => x.SuppressStatusMessages = true);
108-
services.AddSingleton<IHostedService, EmptyHostedService>();
109-
});
110-
return hostBuilder;
106+
Console.WriteLine(BuildHelpParameter(method));
107+
hostBuilder.ConfigureServices(services =>
108+
{
109+
services.AddOptions<ConsoleLifetimeOptions>().Configure(x => x.SuppressStatusMessages = true);
110+
services.AddSingleton<IHostedService, EmptyHostedService>();
111+
});
112+
return hostBuilder;
113+
}
114+
else
115+
{
116+
// override default Help
117+
args = new string[] { "help" };
118+
}
111119
}
112120
}
113121

0 commit comments

Comments
 (0)