public CommandLine(string url) { client = new FunctionsLite(new Uri(url)); application = new CommandLineApplication(); application.HelpOption("-? | -h | --help"); functionCommand = GetFunctionCommand(); }
private void NormalizeCommand(CommandLineApplication command, string description, Func <Task <int> > onExecuteFunction) { command.HelpOption("--help"); command.Description = description; CommandOption debugOption = command.Option("--debug", "Sets logs to verbose", CommandOptionType.NoValue); debugOption.ShowInHelpText = false; CommandOption hostOption = command.Option("--hostUrl", "Sets the host for the controller", CommandOptionType.SingleValue); hostOption.ShowInHelpText = false; command.OnExecute(async() => { if (command.Arguments.Exists(arg => arg.Value == null)) { Console.WriteLine(command.GetHelpText()); return(1); } if (debugOption.HasValue()) { Console.WriteLine("Running command: " + command.Name + "..."); } try { if (hostOption.HasValue()) { client = new FunctionsLite(new Uri(hostOption.Value())); } return(await onExecuteFunction.Invoke()); } catch (Exception e) when(e is Microsoft.Rest.HttpOperationException || e is UriFormatException) { Console.Error.WriteLine("Error communicating with server"); if (debugOption.HasValue()) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } return(1); } }); }