Ejemplo n.º 1
0
        private static void RegisterAddSubcommand(CommandLineApplication packagesCmd, ReportsFactory reportsFactory)
        {
            packagesCmd.Command("add", c =>
            {
                c.Description = "Add a NuGet package to the specified packages folder";
                var argNupkg = c.Argument("[nupkg]", "Path to a NuGet package");
                var argSource = c.Argument("[source]", "Path to packages folder");
                c.HelpOption("-?|-h|--help");

                c.OnExecute(async () =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var options = new AddOptions
                    {
                        Reports = reportsFactory.CreateReports(quiet: false),
                        SourcePackages = argSource.Value,
                        NuGetPackage = argNupkg.Value
                    };
                    var command = new Packages.AddCommand(options);
                    var success = await command.Execute();
                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 2
0
        private static void RegisterUninstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory)
        {
            commandsCmd.Command("uninstall", c =>
            {
                c.Description = "Uninstalls application commands";

                var argCommand = c.Argument("[command]", "The name of the command to uninstall");

                var optNoPurge = c.Option("--no-purge", "Do not try to remove orphaned packages", CommandOptionType.NoValue);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var command = new UninstallCommand(
                        AppCommandsFolderRepository.CreateDefault(),
                        reports: reportsFactory.CreateReports(quiet: false));

                    command.NoPurge = optNoPurge.HasValue();

                    var success = command.Execute(argCommand.Value);
                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 3
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment applicationEnvironment, IServiceProvider serviceProvider)
        {
            cmdApp.Command("publish", c =>
            {
                c.Description = "Publish application for deployment";

                var argProject = c.Argument("[project]", "Path to project, default is current directory");
                var optionOut = c.Option("-o|--out <PATH>", "Where does it go", CommandOptionType.SingleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "The configuration to use for deployment (Debug|Release|{Custom})",
                    CommandOptionType.SingleValue);
                var optionNoSource = c.Option("--no-source", "Compiles the source files into NuGet packages",
                    CommandOptionType.NoValue);
                var optionRuntime = c.Option("--runtime <RUNTIME>", "Name or full path of the runtime folder to include, or \"active\" for current runtime on PATH",
                    CommandOptionType.MultipleValue);
                var optionNative = c.Option("--native", "Build and include native images. User must provide targeted CoreCLR runtime versions along with this option.",
                    CommandOptionType.NoValue);
                var optionIncludeSymbols = c.Option("--include-symbols", "Include symbols in output bundle",
                    CommandOptionType.NoValue);
                var optionWwwRoot = c.Option("--wwwroot <NAME>", "Name of public folder in the project directory",
                    CommandOptionType.SingleValue);
                var optionWwwRootOut = c.Option("--wwwroot-out <NAME>",
                    "Name of public folder in the output, can be used only when the '--wwwroot' option or 'webroot' in project.json is specified",
                    CommandOptionType.SingleValue);
                var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of published files",
                    CommandOptionType.NoValue);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var options = new PublishOptions
                    {
                        OutputDir = optionOut.Value(),
                        ProjectDir = argProject.Value ?? System.IO.Directory.GetCurrentDirectory(),
                        Configuration = optionConfiguration.Value() ?? "Debug",
                        RuntimeTargetFramework = applicationEnvironment.RuntimeFramework,
                        WwwRoot = optionWwwRoot.Value(),
                        WwwRootOut = optionWwwRootOut.Value() ?? optionWwwRoot.Value(),
                        NoSource = optionNoSource.HasValue(),
                        Runtimes = optionRuntime.HasValue() ?
                            string.Join(";", optionRuntime.Values).
                                Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) :
                            new string[0],
                        Native = optionNative.HasValue(),
                        IncludeSymbols = optionIncludeSymbols.HasValue(),
                        Reports = reportsFactory.CreateReports(optionQuiet.HasValue())
                    };

                    var manager = new PublishManager(serviceProvider, options);
                    if (!manager.Publish())
                    {
                        return -1;
                    }

                    return 0;
                });
            });
        }
Ejemplo n.º 4
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment)
        {
            cmdApp.Command("list", c =>
            {
                c.Description = "Print the dependencies of a given project";
                var showAssemblies = c.Option("-a|--assemblies",
                    "Show the assembly files that are depended on by given project",
                    CommandOptionType.NoValue);
                var frameworks = c.Option("--framework <TARGET_FRAMEWORK>",
                    "Show dependencies for only the given frameworks",
                    CommandOptionType.MultipleValue);
                var runtimeFolder = c.Option("--runtime <PATH>",
                    "The folder containing all available framework assemblies",
                    CommandOptionType.SingleValue);
                var details = c.Option("--details",
                    "Show the details of how each dependency is introduced",
                    CommandOptionType.NoValue);
                var mismatched = c.Option("--mismatched",
                    "Show the mismatch dependencies.",
                    CommandOptionType.NoValue);
                var resultsFilter = c.Option("--filter <PATTERN>",
                    "Filter the libraries referenced by the project base on their names. The matching pattern supports * and ?",
                    CommandOptionType.SingleValue);
                var argProject = c.Argument("[project]", "Path to project, default is current directory");
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var options = new DependencyListOptions(reportsFactory.CreateReports(verbose: true, quiet: false), argProject)
                    {
                        ShowAssemblies = showAssemblies.HasValue(),
                        RuntimeFolder = runtimeFolder.Value(),
                        Details = details.HasValue(),
                        ResultsFilter = resultsFilter.Value(),
                        Mismatched = mismatched.HasValue()
                    };
                    options.AddFrameworkMonikers(frameworks.Values);

                    if (!options.Valid)
                    {
                        if (options.Project == null)
                        {
                            options.Reports.Error.WriteLine(string.Format("Unable to locate {0}.".Red(), Runtime.Project.ProjectFileName));
                            return 1;
                        }
                        else
                        {
                            options.Reports.Error.WriteLine("Invalid options.".Red());
                            return 2;
                        }
                    }

                    var command = new DependencyListCommand(options, appEnvironment.RuntimeFramework);
                    return command.Execute();
                });
            });
        }
Ejemplo n.º 5
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("sources", cmd =>
            {
                cmd.Description = "Commands related managing packages source code from external repositories.";
                cmd.HelpOption("-?|-h|--help");
                cmd.OnExecute(() =>
                {
                    cmd.ShowHelp();
                    return 2;
                });

                RegisterGetSubcommand(cmd, reportsFactory);
            });
        }
Ejemplo n.º 6
0
 public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
 {
     cmdApp.Command("clear-http-cache", c =>
     {
         c.Description = "Clears the package cache.";
         c.HelpOption("-?|-h|--help");
         c.OnExecute(() =>
         {
             var command = new ClearCacheCommand(
                 reportsFactory.CreateReports(quiet: false),
                 DnuEnvironment.GetFolderPath(DnuFolderPath.HttpCacheDirectory));       
             return command.Execute();
         });
     });
 }
Ejemplo n.º 7
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("feeds", c =>
            {
                c.Description = "Commands related to managing package feeds currently in use";
                c.HelpOption("-?|-h|--help");
                c.OnExecute(() =>
                {
                    c.ShowHelp();
                    return 2;
                });

                RegisterListCommand(c, reportsFactory);
            });
        }
Ejemplo n.º 8
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment)
        {
            cmdApp.Command("install", c =>
            {
                c.Description = "Install the given dependency";

                var argName = c.Argument("[name]", "Name of the dependency to add");
                var argVersion = c.Argument("[version]", "Version of the dependency to add, default is the latest version.");
                var argProject = c.Argument("[project]", "Path to project, default is current directory");

                var feedCommandLineOptions = FeedCommandLineOptions.Add(c);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(async () =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var feedOptions = feedCommandLineOptions.GetOptions();
                    var reports = reportsFactory.CreateReports(feedOptions.Quiet);

                    var addCmd = new AddCommand();
                    addCmd.Reports = reports;
                    addCmd.Name = argName.Value;
                    addCmd.Version = argVersion.Value;
                    addCmd.ProjectDir = argProject.Value;

                    var restoreCmd = new RestoreCommand(appEnvironment);
                    restoreCmd.Reports = reports;
                    restoreCmd.FeedOptions = feedOptions;

                    restoreCmd.RestoreDirectories.Add(argProject.Value);

                    if (!string.IsNullOrEmpty(feedOptions.Proxy))
                    {
                        Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy);
                    }

                    var installCmd = new InstallCommand(addCmd, restoreCmd);
                    installCmd.Reports = reports;

                    var success = await installCmd.ExecuteCommand();

                    return success ? 0 : 1;
                });
            });

        }
Ejemplo n.º 9
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment)
        {
            cmdApp.Command("commands", cmd =>
            {
                cmd.Description = "Commands related to managing application commands (install, uninstall)";
                cmd.HelpOption("-?|-h|--help");
                cmd.OnExecute(() =>
                {
                    cmd.ShowHelp();
                    return 2;
                });

                RegisterInstallSubcommand(cmd, reportsFactory, appEnvironment);
                RegisterUninstallSubcommand(cmd, reportsFactory);
            });
        }
Ejemplo n.º 10
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment applicationEnvironment, IRuntimeEnvironment runtimeEnvironment)
        {
            cmdApp.Command("restore", c =>
            {
                c.Description = "Restore packages";

                var argRoot = c.Argument("[root]",
                    "List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.",
                    multipleValues: true);
                var feedCommandLineOptions = FeedCommandLineOptions.Add(c);
                var optLock = c.Option("--lock",
                    "Creates dependencies file with locked property set to true. Overwrites file if it exists.",
                    CommandOptionType.NoValue);
                var optUnlock = c.Option("--unlock",
                    "Creates dependencies file with locked property set to false. Overwrites file if it exists.",
                    CommandOptionType.NoValue);
                var optRuntimes = c.Option("--runtime <RID>",
                    "List of runtime identifiers to restore for",
                    CommandOptionType.MultipleValue);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(async () =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var feedOptions = feedCommandLineOptions.GetOptions();
                    var command = new RestoreCommand(applicationEnvironment);
                    command.Reports = reportsFactory.CreateReports(feedOptions.Quiet);
                    command.RestoreDirectories.AddRange(argRoot.Values);
                    command.FeedOptions = feedOptions;
                    command.Lock = optLock.HasValue();
                    command.Unlock = optUnlock.HasValue();
                    command.RequestedRuntimes = optRuntimes.Values;
                    command.FallbackRuntimes = runtimeEnvironment.GetDefaultRestoreRuntimes();

                    if (!string.IsNullOrEmpty(feedOptions.Proxy))
                    {
                        Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy);
                    }

                    var success = await command.Execute();

                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 11
0
        private static void RegisterInstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment)
        {
            commandsCmd.Command("install", c =>
            {
                c.Description = "Installs application commands";

                var argPackage = c.Argument("[package]", "The name of the application package");
                var argVersion = c.Argument("[version]", "The version of the application package");

                var optOverwrite = c.Option("-o|--overwrite", "Overwrites package and conflicting commands", CommandOptionType.NoValue);

                var feedCommandLineOptions = FeedCommandLineOptions.Add(c);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(async () =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var feedOptions = feedCommandLineOptions.GetOptions();
                    var command = new InstallGlobalCommand(
                            appEnvironment,
                            string.IsNullOrEmpty(feedOptions.TargetPackagesFolder) ?
                                AppCommandsFolderRepository.CreateDefault() :
                                AppCommandsFolderRepository.Create(feedOptions.TargetPackagesFolder));

                    command.FeedOptions = feedOptions;
                    command.Reports = reportsFactory.CreateReports(feedOptions.Quiet);
                    command.OverwriteCommands = optOverwrite.HasValue();

                    if (feedOptions.Proxy != null)
                    {
                        Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy);
                    }

                    if (argPackage.Value == null)
                    {
                        c.ShowHelp();
                        return 2;
                    }

                    var success = await command.Execute(argPackage.Value, argVersion.Value);
                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 12
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("packages", packagesCommand =>
            {
                packagesCommand.Description = "Commands related to managing local and remote packages folders";
                packagesCommand.HelpOption("-?|-h|--help");
                packagesCommand.OnExecute(() =>
                {
                    packagesCommand.ShowHelp();
                    return 2;
                });

                RegisterAddSubcommand(packagesCommand, reportsFactory);
                RegisterPushSubcommand(packagesCommand, reportsFactory);
                RegisterPullSubcommand(packagesCommand, reportsFactory);
            });
        }
Ejemplo n.º 13
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("packages", packagesCommand =>
            {
                packagesCommand.Description = "Commands related to managing local and remote packages folders";
                packagesCommand.HelpOption("-?|-h|--help");
                packagesCommand.OnExecute(() =>
                {
                    packagesCommand.ShowHelp();
                    return(2);
                });

                RegisterAddSubcommand(packagesCommand, reportsFactory);
                RegisterPushSubcommand(packagesCommand, reportsFactory);
                RegisterPullSubcommand(packagesCommand, reportsFactory);
            });
        }
Ejemplo n.º 14
0
        public int Main(string[] args)
        {
            #if DEBUG
            // Add our own debug helper because DNU is usually run from a wrapper script,
            // making it too late to use the DNX one. Technically it's possible to use
            // the DNX_OPTIONS environment variable, but that's difficult to do per-command
            // on Windows
            if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
                Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
                Console.WriteLine("Waiting for Debugger to attach...");
                SpinWait.SpinUntil(() => Debugger.IsAttached);
            }
            #endif
            var app = new CommandLineApplication();
            app.Name = "dnu";
            app.FullName = "Microsoft .NET Development Utility";

            var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
            app.HelpOption("-?|-h|--help");
            app.VersionOption("--version", () => _runtimeEnv.GetShortVersion(), () => _runtimeEnv.GetFullVersion());

            // Show help information if no subcommand/option was specified
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return 2;
            });

            var reportsFactory = new ReportsFactory(_runtimeEnv, optionVerbose.HasValue());

            BuildConsoleCommand.Register(app, reportsFactory, _hostServices);
            CommandsConsoleCommand.Register(app, reportsFactory, _environment);
            InstallConsoleCommand.Register(app, reportsFactory, _environment);
            ListConsoleCommand.Register(app, reportsFactory, _environment);
            PackConsoleCommand.Register(app, reportsFactory, _hostServices);
            PackagesConsoleCommand.Register(app, reportsFactory);
            PublishConsoleCommand.Register(app, reportsFactory, _environment, _hostServices);
            RestoreConsoleCommand.Register(app, reportsFactory, _environment);
            SourcesConsoleCommand.Register(app, reportsFactory);
            WrapConsoleCommand.Register(app, reportsFactory);
            FeedsConsoleCommand.Register(app, reportsFactory);

            return app.Execute(args);
        }
Ejemplo n.º 15
0
        public int Main(string[] args)
        {
#if DEBUG
            // Add our own debug helper because DNU is usually run from a wrapper script,
            // making it too late to use the DNX one. Technically it's possible to use
            // the DNX_OPTIONS environment variable, but that's difficult to do per-command
            // on Windows
            if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
                Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
                Console.WriteLine("Waiting for Debugger to attach...");
                SpinWait.SpinUntil(() => Debugger.IsAttached);
            }
#endif
            var app = new CommandLineApplication();
            app.Name     = "dnu";
            app.FullName = "Microsoft .NET Development Utility";

            var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
            app.HelpOption("-?|-h|--help");
            app.VersionOption("--version", () => _runtimeEnv.GetShortVersion(), () => _runtimeEnv.GetFullVersion());

            // Show help information if no subcommand/option was specified
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(2);
            });

            var reportsFactory = new ReportsFactory(_runtimeEnv, optionVerbose.HasValue());

            BuildConsoleCommand.Register(app, reportsFactory, _hostServices);
            CommandsConsoleCommand.Register(app, reportsFactory, _environment);
            InstallConsoleCommand.Register(app, reportsFactory, _environment);
            ListConsoleCommand.Register(app, reportsFactory, _environment);
            PackConsoleCommand.Register(app, reportsFactory, _hostServices);
            PackagesConsoleCommand.Register(app, reportsFactory);
            PublishConsoleCommand.Register(app, reportsFactory, _environment, _hostServices);
            RestoreConsoleCommand.Register(app, reportsFactory, _environment);
            SourcesConsoleCommand.Register(app, reportsFactory);
            WrapConsoleCommand.Register(app, reportsFactory);
            FeedsConsoleCommand.Register(app, reportsFactory);

            return(app.Execute(args));
        }
Ejemplo n.º 16
0
        private static void RegisterPullSubcommand(CommandLineApplication packagesCmd, ReportsFactory reportsFactory)
        {
            packagesCmd.Command("pull", c =>
            {
                c.Description = "Incremental copy of files from remote location to local packages";
                var argRemote = c.Argument("[remote]", "Path to remote packages folder");
                var argSource = c.Argument("[source]",
                    "Path to source packages folder, default is current directory");
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var reports = reportsFactory.CreateReports(quiet: false);

                    bool success;
                    if (Directory.Exists(argSource.Value))
                    {
                        // Implicitly commit changes before pull
                        var commitOptions = new CommitOptions
                        {
                            Reports = reports,
                            SourcePackages = argSource.Value
                        };
                        var commitCommand = new CommitCommand(commitOptions);
                        success = commitCommand.Execute();
                        if (!success)
                        {
                            return 1;
                        }
                    }

                    var pullOptions = new PullOptions
                    {
                        Reports = reports,
                        SourcePackages = argSource.Value,
                        RemotePackages = argRemote.Value
                    };
                    var pullCommand = new PullCommand(pullOptions);
                    success = pullCommand.Execute();
                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 17
0
        public static void RegisterListCommand(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("list", c =>
            {
                c.Description = "Displays a list of package sources in effect for a project";
                var argRoot   = c.Argument("[root]",
                                           "The path of the project to calculate effective package sources for (defaults to the current directory)");

                c.OnExecute(() =>
                {
                    var command = new ListFeedsCommand(
                        reportsFactory.CreateReports(quiet: false),
                        string.IsNullOrEmpty(argRoot.Value) ? "." : argRoot.Value);

                    return(command.Execute());
                });
            });
        }
Ejemplo n.º 18
0
        public static void RegisterListCommand(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("list", c =>
            {
                c.Description = "Displays a list of package sources in effect for a project";
                var argRoot = c.Argument("[root]",
                    "The path of the project to calculate effective package sources for (defaults to the current directory)");

                c.OnExecute(() =>
                {
                    var command = new ListFeedsCommand(
                        reportsFactory.CreateReports(quiet: false),
                        string.IsNullOrEmpty(argRoot.Value) ? "." : argRoot.Value);

                    return command.Execute();
                });
            });
        }
Ejemplo n.º 19
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IServiceProvider serviceProvider)
        {
            cmdApp.Command("build", c =>
            {
                c.Description = "Produce assemblies for the project in given directory";

                var optionFramework     = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue);
                var optionOut           = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
                var optionQuiet         = c.Option("--quiet", "Do not show output such as dependencies in use",
                                                   CommandOptionType.NoValue);
                var argProjectDir = c.Argument(
                    "[projects]",
                    "One or more projects build. If not specified, the project in the current directory will be used.",
                    multipleValues: true);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var buildOptions             = new BuildOptions();
                    buildOptions.OutputDir       = optionOut.Value();
                    buildOptions.ProjectPatterns = argProjectDir.Values;
                    if (buildOptions.ProjectPatterns.Count == 0)
                    {
                        buildOptions.ProjectPatterns.Add(Path.Combine(Directory.GetCurrentDirectory(), "project.json"));
                    }
                    buildOptions.Configurations = optionConfiguration.Values;
                    buildOptions.AddFrameworkMonikers(optionFramework.Values);
                    buildOptions.GeneratePackages = false;
                    buildOptions.Reports          = reportsFactory.CreateReports(optionQuiet.HasValue());

                    var projectManager = new BuildManager(serviceProvider, buildOptions);

                    if (!projectManager.Build())
                    {
                        return(-1);
                    }

                    return(0);
                });
            });
        }
Ejemplo n.º 20
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IServiceProvider serviceProvider)
        {
            cmdApp.Command("pack", c =>
            {
                c.Description = "Build NuGet packages for the project in given directory";

                var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue);
                var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
                var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of nupkgs",
                    CommandOptionType.NoValue);
                var argProjectDir = c.Argument(
                    "[projects]",
                    "One or more projects to pack, default is current directory",
                    multipleValues: true);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var buildOptions = new BuildOptions();
                    buildOptions.OutputDir = optionOut.Value();
                    buildOptions.ProjectPatterns = argProjectDir.Values;
                    if (buildOptions.ProjectPatterns.Count == 0)
                    {
                        buildOptions.ProjectPatterns.Add(Path.Combine(Directory.GetCurrentDirectory(), "project.json"));
                    }
                    buildOptions.Configurations = optionConfiguration.Values;
                    buildOptions.TargetFrameworks = optionFramework.Values;
                    buildOptions.GeneratePackages = true;
                    buildOptions.Reports = reportsFactory.CreateReports(optionQuiet.HasValue());

                    var projectManager = new BuildManager(serviceProvider, buildOptions);

                    if (!projectManager.Build())
                    {
                        return -1;
                    }

                    return 0;
                });
            });
        }
Ejemplo n.º 21
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("pack", c =>
            {
                c.Description = "Build NuGet packages for the project in given directory";

                var optionFramework     = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue);
                var optionOut           = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
                var optionQuiet         = c.Option("--quiet", "Do not show output such as source/destination of nupkgs",
                                                   CommandOptionType.NoValue);
                var argProjectDir = c.Argument(
                    "[projects]",
                    "One or more projects to pack, default is current directory",
                    multipleValues: true);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var buildOptions             = new BuildOptions();
                    buildOptions.OutputDir       = optionOut.Value();
                    buildOptions.ProjectPatterns = argProjectDir.Values;
                    if (buildOptions.ProjectPatterns.Count == 0)
                    {
                        buildOptions.ProjectPatterns.Add(Path.Combine(Directory.GetCurrentDirectory(), "project.json"));
                    }
                    buildOptions.Configurations = optionConfiguration.Values;
                    buildOptions.AddFrameworkMonikers(optionFramework.Values);
                    buildOptions.GeneratePackages = true;
                    buildOptions.Reports          = reportsFactory.CreateReports(optionQuiet.HasValue());

                    var projectManager = new BuildManager(buildOptions);

                    if (!projectManager.Build())
                    {
                        return(1);
                    }

                    return(0);
                });
            });
        }
Ejemplo n.º 22
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("build", c =>
            {
                c.Description = "Produce assemblies for the project in given directory";

                var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue);
                var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
                var optionQuiet = c.Option("--quiet", "Do not show output such as dependencies in use",
                    CommandOptionType.NoValue);
                var argProjectDir = c.Argument(
                    "[projects]",
                    "One or more projects build. If not specified, the project in the current directory will be used.",
                    multipleValues: true);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var buildOptions = new BuildOptions();
                    buildOptions.OutputDir = optionOut.Value();
                    buildOptions.ProjectPatterns = argProjectDir.Values;
                    if (buildOptions.ProjectPatterns.Count == 0)
                    {
                        buildOptions.ProjectPatterns.Add(Path.Combine(Directory.GetCurrentDirectory(), "project.json"));
                    }
                    buildOptions.Configurations = optionConfiguration.Values;
                    buildOptions.AddFrameworkMonikers(optionFramework.Values);
                    buildOptions.GeneratePackages = false;
                    buildOptions.Reports = reportsFactory.CreateReports(optionQuiet.HasValue());

                    var projectManager = new BuildManager(buildOptions);

                    if (!projectManager.Build())
                    {
                        return 1;
                    }

                    return 0;
                });
            });
        }
Ejemplo n.º 23
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment applicationEnvironment)
        {
            cmdApp.Command("restore", c =>
            {
                c.Description = "Restore packages";

                var argRoot = c.Argument("[root]",
                                         "List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.",
                                         multipleValues: true);
                var feedCommandLineOptions = FeedCommandLineOptions.Add(c);
                var optLock = c.Option("--lock",
                                       "Creates dependencies file with locked property set to true. Overwrites file if it exists.",
                                       CommandOptionType.NoValue);
                var optUnlock = c.Option("--unlock",
                                         "Creates dependencies file with locked property set to false. Overwrites file if it exists.",
                                         CommandOptionType.NoValue);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(async() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var feedOptions = feedCommandLineOptions.GetOptions();
                    var command     = new RestoreCommand(applicationEnvironment);
                    command.Reports = reportsFactory.CreateReports(feedOptions.Quiet);
                    command.RestoreDirectories.AddRange(argRoot.Values);
                    command.FeedOptions = feedOptions;
                    command.Lock        = optLock.HasValue();
                    command.Unlock      = optUnlock.HasValue();

                    if (!string.IsNullOrEmpty(feedOptions.Proxy))
                    {
                        Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy);
                    }

                    var success = await command.Execute();

                    return(success ? 0 : 1);
                });
            });
        }
Ejemplo n.º 24
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("wrap", c =>
            {
                c.Description = "Wrap a csproj/assembly into a project.json, which can be referenced by project.json files";

                var argPath = c.Argument("[path]", "Path to csproj/assembly to be wrapped");
                var optConfiguration = c.Option("--configuration <CONFIGURATION>",
                    "Configuration of wrapped project, default is 'debug'", CommandOptionType.SingleValue);
                var optMsBuildPath = c.Option("--msbuild <PATH>",
                    @"Path to MSBuild, default is '%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe'",
                    CommandOptionType.SingleValue);
                var optInPlace = c.Option("-i|--in-place",
                    "Generate or update project.json files in project directories of csprojs",
                    CommandOptionType.NoValue);
                var optFramework = c.Option("-f|--framework",
                    "Target framework of assembly to be wrapped",
                    CommandOptionType.SingleValue);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var reports = reportsFactory.CreateReports(quiet: false);

                    var command = new WrapCommand();
                    command.Reports = reports;
                    command.InputFilePath = argPath.Value;
                    command.Configuration = optConfiguration.Value();
                    command.MsBuildPath = optMsBuildPath.Value();
                    command.InPlace = optInPlace.HasValue();
                    command.Framework = optFramework.Value();

                    var success = command.Execute();

                    return success ? 0 : 1;
                });
            });
        }
Ejemplo n.º 25
0
        private static void RegisterGetSubcommand(CommandLineApplication sourcesCmd, ReportsFactory reportsFactory)
        {
            sourcesCmd.Command("get", c =>
            {
                c.Description = "Retrieves the source code for packages used by projects";

                var packagesArgument = c.Argument(
                    "[package]",
                    "The name of the package for which to retrieve the sources. Can only specify packages used by the project.",
                    multipleValues: true);

                var projectFileOption = c.Option(
                    "-p|--project",
                    "Optional. The path to a project.json file. If not specified, the project in the current folder is used.",
                    CommandOptionType.SingleValue);
                var packagesFolderOption = c.Option(
                    "--packages",
                    "Optional. The local packages folder",
                    CommandOptionType.SingleValue);
                var sourceFolderOption = c.Option(
                    "-o|--output",
                    "Optional. The path to the folder that will hold the source files.",
                    CommandOptionType.SingleValue);

                c.OnExecute(() =>
                {
                    var command = new SourceCommand(packagesArgument.Value, reportsFactory.CreateReports(quiet: false));
                    command.ProjectFile = projectFileOption.Value();
                    command.PackagesFolder = packagesFolderOption.Value();
                    command.SourcesFolder = sourceFolderOption.Value();

                    if (!command.Execute())
                    {
                        return -1;
                    }

                    return 0;
                });
            });
        }
Ejemplo n.º 26
0
        private static void RegisterGetSubcommand(CommandLineApplication sourcesCmd, ReportsFactory reportsFactory)
        {
            sourcesCmd.Command("get", c =>
            {
                c.Description = "Retrieves the source code for packages used by projects";

                var packagesArgument = c.Argument(
                    "[package]",
                    "The name of the package for which to retrieve the sources. Can only specify packages used by the project.",
                    multipleValues: true);

                var projectFileOption = c.Option(
                    "-p|--project",
                    "Optional. The path to a project.json file. If not specified, the project in the current folder is used.",
                    CommandOptionType.SingleValue);
                var packagesFolderOption = c.Option(
                    "--packages",
                    "Optional. The local packages folder",
                    CommandOptionType.SingleValue);
                var sourceFolderOption = c.Option(
                    "-o|--output",
                    "Optional. The path to the folder that will hold the source files.",
                    CommandOptionType.SingleValue);

                c.OnExecute(() =>
                {
                    var command            = new SourceCommand(packagesArgument.Value, reportsFactory.CreateReports(quiet: false));
                    command.ProjectFile    = projectFileOption.Value();
                    command.PackagesFolder = packagesFolderOption.Value();
                    command.SourcesFolder  = sourceFolderOption.Value();

                    if (!command.Execute())
                    {
                        return(-1);
                    }

                    return(0);
                });
            });
        }
Ejemplo n.º 27
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
        {
            cmdApp.Command("wrap", c =>
            {
                c.Description = "Wrap a csproj/assembly into a project.json, which can be referenced by project.json files";

                var argPath          = c.Argument("[path]", "Path to csproj/assembly to be wrapped");
                var optConfiguration = c.Option("--configuration <CONFIGURATION>",
                                                "Configuration of wrapped project, default is 'debug'", CommandOptionType.SingleValue);
                var optMsBuildPath = c.Option("--msbuild <PATH>",
                                              @"Path to MSBuild, default is '%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe'",
                                              CommandOptionType.SingleValue);
                var optInPlace = c.Option("-i|--in-place",
                                          "Generate or update project.json files in project directories of csprojs",
                                          CommandOptionType.NoValue);
                var optFramework = c.Option("-f|--framework",
                                            "Target framework of assembly to be wrapped",
                                            CommandOptionType.SingleValue);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var reports = reportsFactory.CreateReports(quiet: false);

                    var command           = new WrapCommand();
                    command.Reports       = reports;
                    command.InputFilePath = argPath.Value;
                    command.Configuration = optConfiguration.Value();
                    command.MsBuildPath   = optMsBuildPath.Value();
                    command.InPlace       = optInPlace.HasValue();
                    command.Framework     = optFramework.Value();

                    var success = command.Execute();

                    return(success ? 0 : 1);
                });
            });
        }
Ejemplo n.º 28
0
        public static int Main(string[] args)
        {
#if DNX451
            ServicePointManager.DefaultConnectionLimit = 1024;

            // Work around a Mono issue that makes restore unbearably slow,
            // due to some form of contention when requests are processed
            // concurrently. Restoring sequentially is *much* faster in this case.
            if (RuntimeEnvironmentHelper.IsMono)
            {
                ServicePointManager.DefaultConnectionLimit = 1;
            }
#endif

#if DEBUG
            // Add our own debug helper because DNU is usually run from a wrapper script,
            // making it too late to use the DNX one. Technically it's possible to use
            // the DNX_OPTIONS environment variable, but that's difficult to do per-command
            // on Windows
            if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
                Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
                Console.WriteLine("Waiting for Debugger to attach...");
                SpinWait.SpinUntil(() => Debugger.IsAttached);
            }
#endif

            var environment = PlatformServices.Default.Application;
            var runtimeEnv  = PlatformServices.Default.Runtime;

            var app = new CommandLineApplication();
            app.Name     = "dnu";
            app.FullName = "Microsoft .NET Development Utility";

            var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
            app.HelpOption("-?|-h|--help");
            app.VersionOption("--version", () => runtimeEnv.GetShortVersion(), () => runtimeEnv.GetFullVersion());

            // Show help information if no subcommand/option was specified
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(2);
            });

            // Defer reading option verbose until AFTER execute.
            var reportsFactory = new ReportsFactory(runtimeEnv, () => optionVerbose.HasValue());

            BuildConsoleCommand.Register(app, reportsFactory);
            CommandsConsoleCommand.Register(app, reportsFactory, environment);
            InstallConsoleCommand.Register(app, reportsFactory, environment);
            ListConsoleCommand.Register(app, reportsFactory, environment);
            PackConsoleCommand.Register(app, reportsFactory);
            PackagesConsoleCommand.Register(app, reportsFactory);
            PublishConsoleCommand.Register(app, reportsFactory, environment);
            RestoreConsoleCommand.Register(app, reportsFactory, environment, runtimeEnv);
            WrapConsoleCommand.Register(app, reportsFactory);
            FeedsConsoleCommand.Register(app, reportsFactory);
            ClearCacheConsoleCommand.Register(app, reportsFactory);

            try
            {
                return(app.Execute(args));
            }
            catch (CommandParsingException ex)
            {
                AnsiConsole.GetError(useConsoleColor: runtimeEnv.OperatingSystem == "Windows").WriteLine($"Error: {ex.Message}".Red().Bold());
                ex.Command.ShowHelp();
                return(1);
            }
#if DEBUG
            catch
            {
                throw;
            }
Ejemplo n.º 29
0
        public static int Main(string[] args)
        {
#if DNX451
            ServicePointManager.DefaultConnectionLimit = 1024;

            // Work around a Mono issue that makes restore unbearably slow,
            // due to some form of contention when requests are processed
            // concurrently. Restoring sequentially is *much* faster in this case.
            if (RuntimeEnvironmentHelper.IsMono)
            {
                ServicePointManager.DefaultConnectionLimit = 1;
            }
#endif

#if DEBUG
            // Add our own debug helper because DNU is usually run from a wrapper script,
            // making it too late to use the DNX one. Technically it's possible to use
            // the DNX_OPTIONS environment variable, but that's difficult to do per-command
            // on Windows
            if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
            {
                args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
                Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
                Console.WriteLine("Waiting for Debugger to attach...");
                SpinWait.SpinUntil(() => Debugger.IsAttached);
            }
#endif

            var environment = PlatformServices.Default.Application;
            var runtimeEnv = PlatformServices.Default.Runtime;

            var app = new CommandLineApplication();
            app.Name = "dnu";
            app.FullName = "Microsoft .NET Development Utility";

            var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
            app.HelpOption("-?|-h|--help");
            app.VersionOption("--version", () => runtimeEnv.GetShortVersion(), () => runtimeEnv.GetFullVersion());

            // Show help information if no subcommand/option was specified
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return 2;
            });

            // Defer reading option verbose until AFTER execute.
            var reportsFactory = new ReportsFactory(runtimeEnv, () => optionVerbose.HasValue());

            BuildConsoleCommand.Register(app, reportsFactory);
            CommandsConsoleCommand.Register(app, reportsFactory, environment);
            InstallConsoleCommand.Register(app, reportsFactory, environment);
            ListConsoleCommand.Register(app, reportsFactory, environment);
            PackConsoleCommand.Register(app, reportsFactory);
            PackagesConsoleCommand.Register(app, reportsFactory);
            PublishConsoleCommand.Register(app, reportsFactory, environment);
            RestoreConsoleCommand.Register(app, reportsFactory, environment, runtimeEnv);
            WrapConsoleCommand.Register(app, reportsFactory);
            FeedsConsoleCommand.Register(app, reportsFactory);
            ClearCacheConsoleCommand.Register(app, reportsFactory);

            try
            {
                return app.Execute(args);
            }
            catch (CommandParsingException ex)
            {
                AnsiConsole.GetError(useConsoleColor: runtimeEnv.OperatingSystem == "Windows").WriteLine($"Error: {ex.Message}".Red().Bold());
                ex.Command.ShowHelp();
                return 1;
            }
#if DEBUG
            catch
            {
                throw;
            }
#else
            catch (AggregateException aex)
            {
                foreach (var exception in aex.InnerExceptions)
                {
                    DumpException(exception, runtimeEnv);
                }
                return 1;
            }
            catch (Exception ex)
            {
                DumpException(ex, runtimeEnv);
                return 1;
            }
#endif
        }
Ejemplo n.º 30
0
        public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment applicationEnvironment, IServiceProvider serviceProvider)
        {
            cmdApp.Command("publish", c =>
            {
                c.Description = "Publish application for deployment";

                var argProject          = c.Argument("[project]", "Path to project, default is current directory");
                var optionOut           = c.Option("-o|--out <PATH>", "Where does it go", CommandOptionType.SingleValue);
                var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "The configuration to use for deployment (Debug|Release|{Custom})",
                                                   CommandOptionType.SingleValue);
                var optionNoSource = c.Option("--no-source", "Compiles the source files into NuGet packages",
                                              CommandOptionType.NoValue);
                var optionFramework = c.Option(
                    "--framework",
                    "Name of the frameworks to include.",
                    CommandOptionType.MultipleValue);
                var optionIISCommand = c.Option("--iis-command", "Overrides the command name to use in the web.config for the httpPlatformHandler. The default is web.", CommandOptionType.SingleValue);
                var optionRuntime    = c.Option("--runtime <RUNTIME>", "Name or full path of the runtime folder to include, or \"active\" for current runtime on PATH",
                                                CommandOptionType.MultipleValue);
                var optionNative = c.Option("--native", "Build and include native images. User must provide targeted CoreCLR runtime versions along with this option.",
                                            CommandOptionType.NoValue);
                var optionIncludeSymbols = c.Option("--include-symbols", "Include symbols in output bundle",
                                                    CommandOptionType.NoValue);
                var optionWwwRoot = c.Option("--wwwroot <NAME>", "Name of public folder in the project directory",
                                             CommandOptionType.SingleValue);
                var optionWwwRootOut = c.Option("--wwwroot-out <NAME>",
                                                "Name of public folder in the output, can be used only when the '--wwwroot' option or 'webroot' in project.json is specified",
                                                CommandOptionType.SingleValue);
                var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of published files",
                                           CommandOptionType.NoValue);
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var reports = reportsFactory.CreateReports(optionQuiet.HasValue());

                    // Validate the arguments
                    if (optionFramework.HasValue() && optionRuntime.HasValue())
                    {
                        reports.WriteError($"--{optionFramework.LongName} and --{optionRuntime.LongName} cannot be used together.");
                        return(-1);
                    }

                    var options = new PublishOptions
                    {
                        OutputDir              = optionOut.Value(),
                        ProjectDir             = argProject.Value ?? System.IO.Directory.GetCurrentDirectory(),
                        Configuration          = optionConfiguration.Value() ?? "Debug",
                        RuntimeActiveFramework = applicationEnvironment.RuntimeFramework,
                        WwwRoot    = optionWwwRoot.Value(),
                        WwwRootOut = optionWwwRootOut.Value() ?? optionWwwRoot.Value(),
                        NoSource   = optionNoSource.HasValue(),
                        Runtimes   = optionRuntime.HasValue() ?
                                     string.Join(";", optionRuntime.Values).Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) :
                                     new string[0],
                        IISCommand     = optionIISCommand.Value(),
                        Native         = optionNative.HasValue(),
                        IncludeSymbols = optionIncludeSymbols.HasValue(),
                        Reports        = reports
                    };

                    options.AddFrameworkMonikers(optionFramework.Values);

                    var manager = new PublishManager(serviceProvider, options, applicationEnvironment);
                    if (!manager.Publish())
                    {
                        return(-1);
                    }

                    return(0);
                });
            });
        }
Ejemplo n.º 31
0
        private static void RegisterPushSubcommand(CommandLineApplication packagesCmd, ReportsFactory reportsFactory)
        {
            packagesCmd.Command("push", c =>
            {
                c.Description = "Incremental copy of files from local packages to remote location";
                var argRemote = c.Argument("[remote]", "Path to remote packages folder");
                var argSource = c.Argument("[source]",
                                           "Path to source packages folder, default is current directory");
                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var reports = reportsFactory.CreateReports(quiet: false);

                    // Implicitly commit changes before push
                    var commitOptions = new CommitOptions
                    {
                        Reports        = reports,
                        SourcePackages = argSource.Value
                    };
                    var commitCommand = new CommitCommand(commitOptions);
                    var success       = commitCommand.Execute();
                    if (!success)
                    {
                        return(1);
                    }

                    var pushOptions = new PushOptions
                    {
                        Reports        = reports,
                        SourcePackages = argSource.Value,
                        RemotePackages = argRemote.Value
                    };
                    var pushCommand = new PushCommand(pushOptions);
                    success         = pushCommand.Execute();
                    return(success ? 0 : 1);
                });
            });
        }
Ejemplo n.º 32
0
        private static void RegisterAddSubcommand(CommandLineApplication packagesCmd, ReportsFactory reportsFactory)
        {
            packagesCmd.Command("add", c =>
            {
                c.Description = "Add a NuGet package to the specified packages folder";
                var argNupkg  = c.Argument("[nupkg]", "Path to a NuGet package");
                var argSource = c.Argument("[source]", "Path to packages folder");
                c.HelpOption("-?|-h|--help");

                c.OnExecute(async() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var options = new AddOptions
                    {
                        Reports        = reportsFactory.CreateReports(quiet: false),
                        SourcePackages = argSource.Value,
                        NuGetPackage   = argNupkg.Value
                    };
                    var command = new Packages.AddCommand(options);
                    var success = await command.Execute();
                    return(success ? 0 : 1);
                });
            });
        }
Ejemplo n.º 33
0
        private static void RegisterInstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment)
        {
            commandsCmd.Command("install", c =>
            {
                c.Description = "Installs application commands";

                var argPackage = c.Argument("[package]", "The name of the application package");
                var argVersion = c.Argument("[version]", "The version of the application package");

                var optOverwrite = c.Option("-o|--overwrite", "Overwrites package and conflicting commands", CommandOptionType.NoValue);

                var feedCommandLineOptions = FeedCommandLineOptions.Add(c);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(async() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var feedOptions = feedCommandLineOptions.GetOptions();
                    var command     = new InstallGlobalCommand(
                        appEnvironment,
                        string.IsNullOrEmpty(feedOptions.TargetPackagesFolder) ?
                        AppCommandsFolderRepository.CreateDefault() :
                        AppCommandsFolderRepository.Create(feedOptions.TargetPackagesFolder));

                    command.FeedOptions       = feedOptions;
                    command.Reports           = reportsFactory.CreateReports(feedOptions.Quiet);
                    command.OverwriteCommands = optOverwrite.HasValue();

                    if (feedOptions.Proxy != null)
                    {
                        Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy);
                    }

                    if (argPackage.Value == null)
                    {
                        c.ShowHelp();
                        return(2);
                    }

                    var success = await command.Execute(argPackage.Value, argVersion.Value);
                    return(success ? 0 : 1);
                });
            });
        }
Ejemplo n.º 34
0
        private static void RegisterUninstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory)
        {
            commandsCmd.Command("uninstall", c =>
            {
                c.Description = "Uninstalls application commands";

                var argCommand = c.Argument("[command]", "The name of the command to uninstall");

                var optNoPurge = c.Option("--no-purge", "Do not try to remove orphaned packages", CommandOptionType.NoValue);

                c.HelpOption("-?|-h|--help");

                c.OnExecute(() =>
                {
                    c.ShowRootCommandFullNameAndVersion();

                    var command = new UninstallCommand(
                        AppCommandsFolderRepository.CreateDefault(),
                        reports: reportsFactory.CreateReports(quiet: false));

                    command.NoPurge = optNoPurge.HasValue();

                    var success = command.Execute(argCommand.Value);
                    return(success ? 0 : 1);
                });
            });
        }