Exemple #1
0
        public static Task <int> MainCore(string[] args, ILogger log)
        {
            CmdUtils.LaunchDebuggerIfSet(ref args, log);

            var app = new CommandLineApplication
            {
                Name        = "NupkgWrench",
                FullName    = "nupkg wrench",
                Description = "A powertool for modifying nupkg files."
            };

            app.HelpOption(Constants.HelpOption);
            app.VersionOption("--version", (new NuGetVersion(CmdUtils.GetAssemblyVersion())).ToNormalizedString());

            NuspecCommand.Register(app, log);
            FilesCommand.Register(app, log);
            IdCommand.Register(app, log);
            VersionCommand.Register(app, log);
            ExtractCommand.Register(app, log);
            CompressCommand.Register(app, log);
            ListCommand.Register(app, log);
            UpdateFileNameCommand.Register(app, log);
            ReleaseCommand.Register(app, log);
            ValidateCommand.Register(app, log);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(1);
            });

            var exitCode = 1;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (CommandParsingException ex)
            {
                ex.Command.ShowHelp();
            }
            catch (Exception ex)
            {
                ExceptionUtils.LogException(ex, log);
            }

            return(Task.FromResult(exitCode));
        }
Exemple #2
0
        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 assemblyVersion = NuGetVersion.Parse(typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());

            var app = new CommandLineApplication();
            app.Name     = "NupkgWrench";
            app.FullName = "nupkg wrench";
            app.HelpOption(Constants.HelpOption);
            app.VersionOption("--version", assemblyVersion.ToNormalizedString());

            NuspecCommand.Register(app, log);
            FilesCommand.Register(app, log);
            IdCommand.Register(app, log);
            VersionCommand.Register(app, log);
            ExtractCommand.Register(app, log);
            CompressCommand.Register(app, log);
            ListCommand.Register(app, log);
            UpdateFileNameCommand.Register(app, log);
            ReleaseCommand.Register(app, log);
            ValidateCommand.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));
        }