当前位置: 首页>>代码示例>>C#>>正文


C# CommandLineApplication.Execute方法代码示例

本文整理汇总了C#中CommandLineApplication.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineApplication.Execute方法的具体用法?C# CommandLineApplication.Execute怎么用?C# CommandLineApplication.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLineApplication的用法示例。


在下文中一共展示了CommandLineApplication.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Arguments_HaveCorrectDescription_Returns_CorrectValue

        public void Arguments_HaveCorrectDescription_Returns_CorrectValue(
            string propertyName,
            string expectedDescription)
        {
            //Arrange
            var command = new CommandLineApplication();
            var property = typeof(TestClass).GetProperty(propertyName);
            var descriptor = new ParameterDescriptor(property);

            //Act
            descriptor.AddCommandLineParameterTo(command);

            //Assert
            var actualOption = command.Arguments.First();
            Assert.Equal(propertyName, actualOption.Name);
            Assert.Equal(expectedDescription, actualOption.Description);

            //Arrange
            command.Execute(new string[0] { });

            //Assert
            Assert.Equal(null, descriptor.Value); //Is this right assumption to test?

            //Arrange
            command.Execute(new string[] { "PassedValue" });

            //Assert
            Assert.Equal("PassedValue", descriptor.Value);
        }
开发者ID:robbert229,项目名称:Scaffolding,代码行数:29,代码来源:ParameterDescriptorTests.cs

示例2: ExecuteApp

        private static int ExecuteApp(CommandLineApplication app, string[] args)
        {
            // Support Response File
            foreach(var arg in args)
            {
                if(arg.Contains(".rsp"))
                {
                    args = ParseResponseFile(arg);

                    if (args == null)
                    {
                        return 1;
                    }
                }
            }

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
            #if DEBUG
                System.Console.WriteLine(ex);
            #else
                Reporter.Error.WriteLine(ex.Message);
            #endif
                return 1;
            }
        }
开发者ID:niemyjski,项目名称:cli,代码行数:30,代码来源:Program.cs

示例3: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            app.Name = "dotnet compile csc";
            app.FullName = "CSharp compiler";
            app.Description = "CSharp Compiler for the .NET Platform";
            app.HelpOption("-h|--help");

            var responseFileArg = app.Argument("<CONFIG>", "The response file to pass to the compiler.");

            app.OnExecute(() =>
            {
                // Execute CSC!
                var result = RunCsc($"-noconfig @\"{responseFileArg.Value}\"")
                    .ForwardStdErr()
                    .ForwardStdOut()
                    .Execute();

                return result.ExitCode;
            });

            return app.Execute(args);
        }
开发者ID:krwq,项目名称:cli-1,代码行数:25,代码来源:Program.cs

示例4: Main

        public int Main(string[] args)
        {
            try
            {
                var app = new CommandLineApplication
                {
                    Name = "razor-tooling",
                    FullName = "Microsoft Razor Tooling Utility",
                    Description = "Resolves Razor tooling specific information.",
                    ShortVersionGetter = GetInformationalVersion,
                };
                app.HelpOption("-?|-h|--help");

                ResolveProtocolCommand.Register(app);
                ResolveTagHelpersCommand.Register(app, _assemblyLoadContext);

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

                return app.Execute(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {Environment.NewLine}{ex.Message}.");
                return 1;
            }
        }
开发者ID:IlyaKhD,项目名称:RazorTooling,代码行数:30,代码来源:Program.cs

示例5: Main

        public static int Main(string[] args)
        {
            var app = new CommandLineApplication();
            app.Name = "dotnet";
            app.Description = "The .NET CLI";

            // Most commonly used commands
            app.Command("init", c =>
            {
                c.Description = "Scaffold a basic .NET application";

                c.OnExecute(() => Exec("dotnet-init", c.RemainingArguments));
            });

            app.Command("compile", c =>
            {
                c.Description = "Produce assemblies for the project in given directory";

                c.OnExecute(() => Exec("dotnet-compile", c.RemainingArguments));
            });

            app.Command("restore", c =>
            {
                c.Description = "Restore packages";

                c.OnExecute(() => Exec("dotnet-restore", c.RemainingArguments));
            });

            app.Command("pack", c =>
            {
                c.Description = "Produce a NuGet package";

                c.OnExecute(() => Exec("dotnet-pack", c.RemainingArguments));
            });

            app.Command("publish", c =>
            {
                c.Description = "Produce deployable assets";

                c.OnExecute(() => Exec("dotnet-publish", c.RemainingArguments));
            });

            // TODO: Handle unknown commands

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

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return 1;
        }
开发者ID:Sridhar-MS,项目名称:cli-old,代码行数:60,代码来源:Program.cs

示例6: Main

        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "guardrex-json-to-csproj-converter",
                FullName = "GuardRex JSON to CSPROJ Converter",
                Description = "Converts project.json into a .csproj file for the project",
            };
            app.HelpOption("-h|--help");

            var frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework of application being published", CommandOptionType.SingleValue);
            var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Target configuration of application being published", CommandOptionType.SingleValue);
            var projectPath = app.Argument("<PROJECT>", "The path to the project (project folder or project.json) being published. If empty the current directory is used.");

            app.OnExecute(() =>
            {
                var exitCode = new ConvertCommand(frameworkOption.Value(), configurationOption.Value(), projectPath.Value).Run();

                return exitCode;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                Reporter.Output.WriteLine(e.ToString().Yellow());
            }

            return 1;
        }
开发者ID:GuardRex,项目名称:GuardRex.JsonToCsprojConverter,代码行数:33,代码来源:Program.cs

示例7: Run

        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            app.Name = "dotnet publish";
            app.FullName = ".NET Publisher";
            app.Description = "Publisher for the .NET Platform";
            app.HelpOption("-h|--help");

            var framework = app.Option("-f|--framework <FRAMEWORK>", "Target framework to compile for", CommandOptionType.SingleValue);
            var runtime = app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue);
            var buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
            var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue);
            var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory");
            var nativeSubdirectories = app.Option("--native-subdirectory", "Temporary mechanism to include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue);
            var noBuild = app.Option("--no-build", "Do not build projects before publishing", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                var publish = new PublishCommand();

                publish.Framework = framework.Value();
                publish.Runtime = runtime.Value();
                publish.BuildBasePath = buildBasePath.Value();
                publish.OutputPath = output.Value();
                publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration;
                publish.NativeSubdirectories = nativeSubdirectories.HasValue();
                publish.ProjectPath = projectPath.Value;
                publish.VersionSuffix = versionSuffix.Value();
                publish.ShouldBuild = !noBuild.HasValue();

                if (string.IsNullOrEmpty(publish.ProjectPath))
                {
                    publish.ProjectPath = Directory.GetCurrentDirectory();
                }

                if (!publish.TryPrepareForPublish())
                {
                    return 1;
                }

                publish.PublishAllProjects();
                Reporter.Output.WriteLine($"Published {publish.NumberOfPublishedProjects}/{publish.NumberOfProjects} projects successfully");
                return (publish.NumberOfPublishedProjects == publish.NumberOfProjects) ? 0 : 1;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
                Reporter.Error.WriteLine(ex.Message.Red());
                Reporter.Verbose.WriteLine(ex.ToString().Yellow());
                return 1;
            }
        }
开发者ID:krytarowski,项目名称:cli,代码行数:60,代码来源:Program.cs

示例8: Run

        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication(false)
            {
                Name = "dotnet restore",
                FullName = ".NET project dependency restorer",
                Description = "Restores dependencies listed in project.json"
            };


            app.OnExecute(() =>
            {
                try
                {
                    return NuGet3.Restore(args);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);

                    return -1;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return -2;
                }
            });

            return app.Execute(args);
        }
开发者ID:akrisiun,项目名称:dotnet-cli,代码行数:34,代码来源:Program.cs

示例9: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            app.Name = "dotnet init";
            app.FullName = ".NET Initializer";
            app.Description = "Initializes empty project for .NET Platform";
            app.HelpOption("-h|--help");

            var dotnetInit = new Program();
            app.OnExecute((Func<int>)dotnetInit.CreateEmptyProject);

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
            #if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
            #else
                Reporter.Error.WriteLine(ex.Message);
            #endif
                return 1;
            }
        }
开发者ID:niemyjski,项目名称:cli,代码行数:27,代码来源:Program.cs

示例10: Main

        public int Main(string[] args)
        {
            try
            {
                var description = "Creates table and indexes in Microsoft SQL Server database " +
                    "to be used for distributed caching";

                var app = new CommandLineApplication();
                app.Name = "sqlservercache";
                app.Description = description;

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

                app.Command("create", command =>
                {
                    command.Description = description;
                    var connectionStringArg = command.Argument(
                        "[connectionString]",
                        "The connection string to connect to the database.");
                    var schemaNameArg = command.Argument("[schemaName]", "Name of the table schema.");
                    var tableNameArg = command.Argument("[tableName]", "Name of the table to be created.");
                    command.HelpOption("-?|-h|--help");

                    command.OnExecute(() =>
                    {
                        if (string.IsNullOrEmpty(connectionStringArg.Value)
                        || string.IsNullOrEmpty(schemaNameArg.Value)
                        || string.IsNullOrEmpty(tableNameArg.Value))
                        {
                            _logger.LogWarning("Invalid input");
                            app.ShowHelp();
                            return 2;
                        }

                        _connectionString = connectionStringArg.Value;
                        _schemaName = schemaNameArg.Value;
                        _tableName = tableNameArg.Value;

                        CreateTableAndIndexes();

                        return 0;
                    });
                });

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

                return app.Execute(args);
            }
            catch (Exception exception)
            {
                _logger.LogCritical("An error occurred. {Message}", exception.Message);
                return 1;
            }
        }
开发者ID:benaadams,项目名称:Caching,代码行数:59,代码来源:Program.cs

示例11: Run

        public static int Run(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication(false)
            {
                Name = "dotnet restore",
                FullName = ".NET project dependency restorer",
                Description = "Restores dependencies listed in project.json"
            };

            // Parse --quiet, because we have to handle that specially since NuGet3 has a different
            // "--verbosity" switch that goes BEFORE the command
            var quiet = args.Any(s => s.Equals("--quiet", StringComparison.OrdinalIgnoreCase));
            args = args.Where(s => !s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)).ToArray();

            // Until NuGet/Home#1941 is fixed, if no RIDs are specified, add our own.
            if (!args.Any(s => s.Equals("--runtime", StringComparison.OrdinalIgnoreCase)))
            {
                args = Enumerable.Concat(
                    args,
                    PlatformServices.Default.Runtime.GetOverrideRestoreRuntimeIdentifiers().SelectMany(r => new [] { "--runtime", r })
                    ).ToArray();
            }

            app.OnExecute(() =>
            {
                try
                {
                    var projectRestoreResult = NuGet3.Restore(args, quiet);

                    var restoreTasks = GetRestoreTasks(args);

                    foreach (var restoreTask in restoreTasks)
                    {
                        var project = ProjectReader.GetProject(restoreTask.ProjectPath);

                        RestoreTools(project, restoreTask, quiet);
                    }

                    return projectRestoreResult;
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);

                    return -1;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                    return -2;
                }
            });

            return app.Execute(args);
        }
开发者ID:ans-ashkan,项目名称:cli,代码行数:58,代码来源:Program.cs

示例12: Main

        static void Main(string[] args)
        {
            CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);
            CommandArgument directory = commandLineApplication.Argument("directory", "The directory to search for assemblies");
            CommandOption dgmlExport = commandLineApplication.Option("-dg|--dgml <filename>", "Export to a dgml file", CommandOptionType.SingleValue);
            CommandOption nonsystem = commandLineApplication.Option("-n|--nonsystem", "List system assemblies", CommandOptionType.NoValue);
            CommandOption all = commandLineApplication.Option("-a|--all", "List all assemblies and references.", CommandOptionType.NoValue);
            CommandOption noconsole = commandLineApplication.Option("-nc|--noconsole", "Do not show references on console.", CommandOptionType.NoValue);
            CommandOption silent = commandLineApplication.Option("-s|--silent", "Do not show any message, only warnings and errors will be shown.", CommandOptionType.NoValue);

            commandLineApplication.HelpOption("-? | -h | --help");
            commandLineApplication.OnExecute(() =>
            {
                var consoleLogger = new ConsoleLogger(!silent.HasValue());

                var directoryPath = directory.Value;
                if (!Directory.Exists(directoryPath))
                {
                    consoleLogger.LogMessage(string.Format("Directory: '{0}' does not exist.", directoryPath));
                    return -1;
                }

                var onlyConflicts = !all.HasValue();
                var skipSystem = nonsystem.HasValue();

                IDependencyAnalyzer analyzer = new DependencyAnalyzer() { DirectoryInfo = new DirectoryInfo(directoryPath) };

                consoleLogger.LogMessage(string.Format("Check assemblies in: {0}", analyzer.DirectoryInfo));

                var result = analyzer.Analyze(consoleLogger);

                if (!noconsole.HasValue())
                {
                    IDependencyVisualizer visualizer = new ConsoleVisualizer(result) { SkipSystem = skipSystem, OnlyConflicts = onlyConflicts };
                    visualizer.Visualize();
                }

                if (dgmlExport.HasValue())
                {
                    IDependencyVisualizer export = new DgmlExport(result, string.IsNullOrWhiteSpace(dgmlExport.Value()) ? Path.Combine(analyzer.DirectoryInfo.FullName, "references.dgml") : dgmlExport.Value(), consoleLogger);
                    export.Visualize();
                }

                return 0;
            });
            try
            {
                if (args == null || args.Length == 0)
                    commandLineApplication.ShowHelp();
                else
                    commandLineApplication.Execute(args);
            }
            catch (CommandParsingException cpe)
            {
                Console.WriteLine(cpe.Message);
                commandLineApplication.ShowHelp();
            }
        }
开发者ID:mikehadlow,项目名称:AsmSpy,代码行数:58,代码来源:Program.cs

示例13: Main

        public int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "dnx Azure",
                FullName = "Azure Message Queue Utils"
            };

            app.HelpOption(HELP_TEMPLATE);

            app.OnExecute(() => ShowHelp(app));

            app.Command("send", send =>
            {
                send.Description = "Send a message";
                send.HelpOption(HELP_TEMPLATE);

                var queueName = send.Argument("[queueName]", "The name of the queue");
                var message = send.Argument("[message]", "The message to send");
                var connectionString = send.Argument("[connectionString]", "The connection string");

                send.OnExecute(() =>
                {
                    var factory = MessagingFactory.CreateFromConnectionString(connectionString.Value);
                    var queue = factory.CreateQueueClient(queueName.Value);
                    var packet = new BrokeredMessage(message.Value);

                    queue.Send(packet);

                    return 0;
                });
            });

            app.Command("receive", receive =>
            {
                receive.Description = "Receive a message";
                receive.HelpOption(HELP_TEMPLATE);

                var queueName = receive.Argument("[queueName]", "The name of the queue");
                var connectionString = receive.Argument("[connectionString]", "The connection string");

                receive.OnExecute(() =>
                {
                    var factory = MessagingFactory.CreateFromConnectionString(connectionString.Value);
                    var queue = factory.CreateQueueClient(queueName.Value);
                    var message = queue.Receive();

                    Console.WriteLine(message.GetBody<string>());

                    message.Complete(); // must signal to queue that the message has been handled

                    return 0;
                });
            });

            return app.Execute(args);
        }
开发者ID:Kieranties,项目名称:MessagingPlayground,代码行数:57,代码来源:Program.cs

示例14: Main

 static void Main(string[] args)
 {
     var app = new CommandLineApplication();
     app.UseServices(services =>
         services
             .AddServices()
             .ConfigureArguments(args));
     app.ListReferences();
     app.Execute();
 }
开发者ID:NullValueType,项目名称:gilmond-helpers,代码行数:10,代码来源:Program.cs

示例15: Main

        public static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "Project.Json.Patcher",
                Description = "Patch project.json files with new version and release notes",
                FullName = "Project.Json Patcher"
            };

            app.HelpOption("-h|--help");

            app.Command("Patch", commandAppConfing =>
            {
                commandAppConfing.Description = "Patches the project.json file";

                CommandOption fileOption = commandAppConfing.Option("-f|--File <FilePath>",
                    "OPTIONAL. Path to project.json", CommandOptionType.SingleValue);

                CommandOption versionOption = commandAppConfing.Option("-v|--Version <Version>",
                    "Target version of project.json", CommandOptionType.SingleValue);

                CommandOption releaseNotesOption = commandAppConfing.Option("-r|--RealeaseNotes <ReleaseNotes>",
                    "OPTIONAL. Release notes of this version", CommandOptionType.SingleValue);

                commandAppConfing.HelpOption("-h|--help");

                commandAppConfing.OnExecute(() =>
                {

                    string filePath = GetFilePath(fileOption);

                    string version = GetVersion(versionOption);

                    string releaseNotes = releaseNotesOption.Value();

                    Console.WriteLine($"FilePath: {filePath}, " +
                                      $"Version: {version}, " +
                                      $"ReleaseNotes: {releaseNotes}");

                    Patch(filePath, version, releaseNotes);

                    Console.WriteLine("Patching Complete");
                    return 0;
                });

            });

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

            app.Execute(args);
        }
开发者ID:bilal-fazlani,项目名称:Project.Json.Patcher,代码行数:55,代码来源:Program.cs


注:本文中的CommandLineApplication.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。