예제 #1
0
        private static CommandLineApplication InitializeApp(string[] args, CommandOutputLogger log)
        {
            // Many commands don't want prefixes output. Use loggerFunc(log) instead of log to set the HidePrefix property first.
            Func <CommandOutputLogger, Func <ILogger> > loggerFunc = (commandOutputLogger) =>
            {
                commandOutputLogger.HidePrefixForInfoAndMinimal = true;
                return(() => commandOutputLogger);
            };

            var app = new CommandLineApplication();

            if (args.Any() && args[0] == "package")
            {
                // "dotnet * package" commands
                app.Name = DotnetPackageAppName;
                AddPackageReferenceCommand.Register(app, () => log, () => new AddPackageReferenceCommandRunner());
                RemovePackageReferenceCommand.Register(app, () => log, () => new RemovePackageReferenceCommandRunner());
                ListPackageCommand.Register(app, () => log, () => new ListPackageCommandRunner());
            }
            else
            {
                // "dotnet nuget *" commands
                app.Name = DotnetNuGetAppName;
                CommandParsers.Register(app, loggerFunc(log));
                DeleteCommand.Register(app, () => log);
                PushCommand.Register(app, () => log);
                LocalsCommand.Register(app, () => log);
            }

            app.FullName = Strings.App_FullName;
            app.HelpOption(XPlatUtility.HelpOption);
            app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());

            return(app);
        }
예제 #2
0
 private static void RegisterCommands(CommandLineApplication app, CommandOutputLogger log)
 {
     // Register commands
     if (app.Name == DotnetPackageAppName)
     {
         AddPackageReferenceCommand.Register(app, () => log, () => new AddPackageReferenceCommandRunner());
         RemovePackageReferenceCommand.Register(app, () => log, () => new RemovePackageReferenceCommandRunner());
     }
     else
     {
         DeleteCommand.Register(app, () => log);
         PushCommand.Register(app, () => log);
         LocalsCommand.Register(app, () => log);
     }
 }
예제 #3
0
        private static CommandLineApplication InitializeApp(string[] args, CommandOutputLogger log)
        {
            // Many commands don't want prefixes output. Use this func instead of () => log to set the HidePrefix property first.
            Func <ILogger> getHidePrefixLogger = () =>
            {
                log.HidePrefixForInfoAndMinimal = true;
                return(log);
            };

            // Allow commands to set the NuGet log level
            Action <LogLevel> setLogLevel = (logLevel) => log.VerbosityLevel = logLevel;

            var app = new CommandLineApplication();

            if (args.Any() && args[0] == "package")
            {
                // "dotnet * package" commands
                app.Name = DotnetPackageAppName;
                AddPackageReferenceCommand.Register(app, () => log, () => new AddPackageReferenceCommandRunner());
                RemovePackageReferenceCommand.Register(app, () => log, () => new RemovePackageReferenceCommandRunner());
                ListPackageCommand.Register(app, getHidePrefixLogger, setLogLevel, () => new ListPackageCommandRunner());
            }
            else
            {
                // "dotnet nuget *" commands
                app.Name = DotnetNuGetAppName;
                CommandParsers.Register(app, getHidePrefixLogger);
                DeleteCommand.Register(app, getHidePrefixLogger);
                PushCommand.Register(app, getHidePrefixLogger);
                LocalsCommand.Register(app, getHidePrefixLogger);
                VerifyCommand.Register(app, getHidePrefixLogger, setLogLevel, () => new VerifyCommandRunner());
                TrustedSignersCommand.Register(app, getHidePrefixLogger, setLogLevel);
                SignCommand.Register(app, getHidePrefixLogger, setLogLevel, () => new SignCommandRunner());
            }

            app.FullName = Strings.App_FullName;
            app.HelpOption(XPlatUtility.HelpOption);
            app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());

            return(app);
        }