natemcmaster/CommandLineUtils

Optionally running IHostedService, except if there are command lines.

wasabii opened this issue · 5 comments

So, I've got this situation where I have an app that has a bunch of IHostedServices. I'd like to add command line supprot to it, but not actually run the IHostedServices unless the user has NOT passed any command line arguments. The basic idea is it's a Windows Service, but will support some command lines like "install" and "uninstall".

Since CommandLineUtils RunCommandLineAPplicationAsync uses a IHostedService to actually kick itself off, this doesn't quite work. There's no way I can find to have the other services NOT run if there's a command line. Other than to not use RunCommandLineApplicationAsync, parse it all upfront, and not register services if there's a command that says I shouldn't.

Or, I can just not register my services if args has any values in it.

Both are pretty non-ideal. The second obviously requires me to do all the parsing outside of the standard process (and the container). The second requires me to probe args[] outside of the parsing.

Suggestions?

The second obviously requires me to do all the parsing outside of the standard process (and the container).

I would recommend this approach. It's probably cleaner coding anyways to separate concerns (separating parsing command line options from the actual execution of your app code.)

Maybe. But leveraging the container and assembly scanning to assemble subcommands is quite nice.

Feel free to propose changes if you find that some kind of extensibility would make it easier to get the behaviors you want from CommandLineUtils.

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.