commandline
commandline copied to clipboard
--help not quitting program.
calling my console app with single parameter --help or --version is showing the help/version, but then not quitting the app. It continues to run. My setup code is as follows:
var result = Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(o =>
{
if (o.Dest != null && o.Dest.Trim() != "")
{
rootOutputFolder = o.Dest.Trim();
}
else
{
// default to current folder's converted_databases/ subfolder
string? currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (currentFolder == null)
{
throw new Exception("Could not get current folder");
}
rootOutputFolder = Path.Combine(currentFolder, "converted_databases");
if (!Directory.Exists(rootOutputFolder))
{
DirectoryInfo di = Directory.CreateDirectory(rootOutputFolder);
}
}
if (o.Verbose)
{
db.DoLog = true;
Logger.DoOleLog = true;
}
});
public class Options
{
[Option('d', "dest", Required = false, HelpText = "Full path to root output folder for converted databases. If not specified, will default to .\\converted_databases\\")]
public string? Dest { get; set; }
[Option('v', "verbose", Required = false, HelpText = "Log all SQL queries in converter.log.")]
public bool Verbose { get; set; }
}