private static void Run(CommandLineApplication cmd, ILogger log) { cmd.Description = "Create a new sleet.json config file."; var awss3 = cmd.Option("--s3", "Add a template entry for an Amazon S3 storage feed.", CommandOptionType.NoValue); var azure = cmd.Option("--azure", "Add a template entry for an azure storage feed.", CommandOptionType.NoValue); var folder = cmd.Option("--local", "Add a template entry for a local folder feed.", CommandOptionType.NoValue); var output = cmd.Option("--output", "Output path. If not specified the file will be created in the working directory.", CommandOptionType.SingleValue); var verbose = cmd.Option(Constants.VerboseOption, Constants.VerboseDesc, CommandOptionType.NoValue); cmd.HelpOption(Constants.HelpOption); cmd.OnExecute(async() => { // Init logger Util.SetVerbosity(log, verbose.HasValue()); var outputPath = output.HasValue() ? output.Value() : null; var storageType = awss3.HasValue() ? FileSystemStorageType.S3 : azure.HasValue() ? FileSystemStorageType.Azure : folder.HasValue() ? FileSystemStorageType.Local : FileSystemStorageType.Unspecified; var success = await CreateConfigCommand.RunAsync(storageType, outputPath, 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)); }