public int Execute()

in src/Amazon.Common.DotNetCli.Tools/Cli/Application.cs [28:93]


        public int Execute(string[] args)
        {
            try
            {
                PrintToolTitle();

                if (args.Length == 0)
                {
                    PrintUsage();
                    return -1;
                }

                if (IsHelpSwitch(args[0]))
                {
                    if (args.Length > 1)
                        PrintUsage(args[1]);
                    else
                        PrintUsage();

                    return 0;
                }
                else if(args.Length > 1 && IsHelpSwitch(args[1]))
                {
                    PrintUsage(args[0]);
                    return 0;
                }

                var commandInfo = FindCommandInfo(args[0]);


                if (commandInfo != null)
                {
                    var command = commandInfo.CreateCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray());
                    var success = command.ExecuteAsync().Result;
                    if (!success)
                    {
                        return -1;
                    }
                }
                else
                {
                    Console.Error.WriteLine($"Unknown command: {args[0]}\n");
                    PrintUsage();
                    return -1;
                }
            }
            catch (ToolsException e)
            {
                Console.Error.WriteLine(e.Message);
                return -1;
            }
            catch(TargetInvocationException e) when (e.InnerException is ToolsException)
            {
                Console.Error.WriteLine(e.InnerException.Message);
                return -1;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Unknown error:");
                Console.Error.WriteLine(e);

                return -1;
            }

            return 0;
        }