private static void Run(CommandLineApplication cmd, ILogger log) { cmd.Description = "Report feed statistics."; var optionConfigFile = cmd.Option(Constants.ConfigOption, Constants.ConfigDesc, CommandOptionType.SingleValue); var sourceName = cmd.Option(Constants.SourceOption, Constants.SourceDesc, CommandOptionType.SingleValue); var verbose = cmd.Option(Constants.VerboseOption, Constants.VerboseDesc, CommandOptionType.NoValue); var propertyOptions = cmd.Option(Constants.PropertyOption, Constants.PropertyDescription, CommandOptionType.MultipleValue); cmd.HelpOption(Constants.HelpOption); var required = new List <CommandOption>(); cmd.OnExecute(async() => { // Validate parameters CmdUtils.VerifyRequiredOptions(required.ToArray()); // Init logger Util.SetVerbosity(log, verbose.HasValue()); // Create a temporary folder for caching files during the operation. using (var cache = new LocalCache()) { // Load settings and file system. var settings = LocalSettings.Load(optionConfigFile.Value(), SettingsUtility.GetPropertyMappings(propertyOptions.Values)); var fileSystem = Util.CreateFileSystemOrThrow(settings, sourceName.Value(), cache); var success = await StatsCommand.RunAsync(settings, fileSystem, log); return(success ? 0 : 1); } }); }
public static Task <int> MainCore(string[] args, ILogger log) { #if DEBUG if (args.Contains("--debug")) { args = args.Skip(1).ToArray(); while (!Debugger.IsAttached) { } Debugger.Break(); } #endif var app = new CommandLineApplication(); app.Name = "sleet"; app.FullName = "Sleet"; app.HelpOption("-h|--help"); app.VersionOption("--version", Constants.SleetVersion.ToFullVersionString()); InitCommand.Register(app, log); PushCommand.Register(app, log); DeleteCommand.Register(app, log); ValidateCommand.Register(app, log); StatsCommand.Register(app, log); CreateConfigCommand.Register(app, log); app.OnExecute(() => { app.ShowHelp(); return(0); }); var exitCode = 0; try { exitCode = app.Execute(args); } catch (CommandParsingException ex) { ex.Command.ShowHelp(); } catch (AggregateException ex) { exitCode = 1; foreach (var inner in ex.InnerExceptions) { log.LogError(inner.Message); log.LogDebug(inner.ToString()); } } catch (Exception ex) { exitCode = 1; log.LogError(ex.Message); log.LogDebug(ex.ToString()); } return(Task.FromResult(exitCode)); }