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


C# CommandLineApplication.Argument方法代码示例

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


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

示例1: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Set imports for project.json files";

            var argRoot = cmd.Argument(
                "[root]",
                "directory",
                multipleValues: true);

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

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

                foreach (var arg in argRoot.Values)
                {
                    var dir = new DirectoryInfo(arg);

                    foreach (var file in dir.GetFiles("project.json", SearchOption.AllDirectories))
                    {
                        Process(file);
                    }
                }

                return 0;
            });
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:28,代码来源:ImportsCommand.cs

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: Main

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

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

            var output = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue);
            var intermediateOutput = app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");

            app.OnExecute(() =>
            {
                // Locate the project and get the name and full path
                var path = project.Value;
                if (string.IsNullOrEmpty(path))
                {
                    path = Directory.GetCurrentDirectory();
                }

                if(!path.EndsWith(Project.FileName))
                {
                    path = Path.Combine(path, Project.FileName);
                }

                if(!File.Exists(path))
                {
                    Reporter.Error.WriteLine($"Unable to find a project.json in {path}");
                    return 1;
                }

                var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration;
                var outputValue = output.Value();

                return BuildPackage(path, configValue, outputValue, intermediateOutput.Value()) ? 1 : 0;
            });

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

示例7: Main

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

            var app = new CommandLineApplication();
            app.Name = "resgen";
            app.FullName = "Resource compiler";
            app.Description = "Microsoft (R) .NET Resource Generator";
            app.HelpOption("-h|--help");

            var inputFile = app.Argument("<input>", "The .resx file to transform");
            var outputFile = app.Argument("<output>", "The .resources file to produce");

            app.OnExecute(() =>
            {
                WriteResourcesFileIfNotEmpty(inputFile.Value, outputFile.Value);
                return 0;
            });

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

示例8: Main

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

            var app = new CommandLineApplication();
            app.Name = "dotnet repl csi";
            app.FullName = "C# REPL";
            app.Description = "C# REPL for the .NET platform";
            app.HelpOption("-h|--help");
            var script = app.Argument("<SCRIPT>", "The .csx file to run. Defaults to interactive mode.");

            app.OnExecute(() => Run(script.Value));
            return app.Execute(args);
        }
开发者ID:shahid-pk,项目名称:cli,代码行数:14,代码来源:Program.cs

示例9: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Update a package version.";

            var packageId = cmd.Option(
                "-i|--id <id>",
                "package id",
                CommandOptionType.SingleValue);

            var packageVersion = cmd.Option(
                "-v|--version <version>",
                "package version",
                CommandOptionType.SingleValue);

            var argRoot = cmd.Argument(
                "[root]",
                "directory",
                multipleValues: true);

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

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

                if (string.IsNullOrEmpty(packageId.Value()))
                {
                    throw new ArgumentException($"Missing value: {packageId.LongName}");
                }

                VersionRange version;
                if (!VersionRange.TryParse(packageVersion.Value(), out version))
                {
                    throw new ArgumentException($"Invalid value for: {packageVersion.LongName}");
                }

                foreach (var arg in argRoot.Values)
                {
                    var dir = new DirectoryInfo(arg);

                    foreach (var file in dir.GetFiles("project.json", SearchOption.AllDirectories))
                    {
                        Process(file, packageId.Value(), version);
                    }
                }

                return 0;
            });
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:49,代码来源:UpdatePackageCommand.cs

示例10: Main

 public static int Main(string[] args)
 {
   
     var app = new CommandLineApplication();
     app.Name = "dotnet api-search";
     app.FullName = ".NET API CLI search tool";
     app.Description = "Reverse package search using the API as a keyword";
     app.HelpOption("-h|--help");
     
     var url = app.Option("-u|--url", "Overrides for the default URL for the Package Search API", CommandOptionType.SingleValue);
     var query = app.Argument("<QUERY>", "The API to search for in the shape of a single keyword");
     
     
     // var writer = new ConsoleWriter();
     // 
     // if (args.Length == 0)
     // {
     //     ShowHelp();
     //     return 0;
     // }
     
     // We are assuming just a single string on invocation (naive, I know)
     app.OnExecute(() => 
     {
         var apisearch = new ApiSearchCommand();
         apisearch.ApiUrl = url.Value() ?? "http://packagesearch.azurewebsites.net/Search/";
         apisearch.Query = query.Value;
         
         if (String.IsNullOrEmpty(apisearch.Query))
         {
             Reporter.Output.WriteLine("<QUERY> argument is required. Use -h|--help to see help");
             return 0;
         }
         
         return apisearch.SearchApi();
         
     });
     
     try
     {
         return app.Execute(args);
     } 
     catch (Exception ex)
     {
         Reporter.Error.WriteLine(ex.Message.Red());
         return 1;
     } 
 }
开发者ID:blackdwarf,项目名称:cli-commands,代码行数:48,代码来源:Program.cs

示例11: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Update a release label across pacakges.";

            var find = cmd.Option(
                "-f|--find <label>",
                "release label. Ex: alpha-100",
                CommandOptionType.SingleValue);

            var replace = cmd.Option(
                "-r|--replace <label>",
                "release label. Ex: alpha-101",
                CommandOptionType.SingleValue);

            var argRoot = cmd.Argument(
                "[root]",
                "directory",
                multipleValues: true);

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

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

                if (string.IsNullOrEmpty(find.Value()))
                {
                    throw new ArgumentException($"Missing value: {find.LongName}");
                }

                if (string.IsNullOrEmpty(replace.Value()))
                {
                    throw new ArgumentException($"Missing value: {replace.LongName}");
                }

                foreach (var arg in argRoot.Values)
                {
                    var dir = new DirectoryInfo(arg);

                    foreach (var file in dir.GetFiles("project.json", SearchOption.AllDirectories))
                    {
                        Process(file, find.Value(), replace.Value());
                    }
                }

                return 0;
            });
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:48,代码来源:UpdateReleaseLabelCommand.cs

示例12: Run

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

            var app = new CommandLineApplication(throwOnUnexpectedArg: false) {
                Name = AppName,
                FullName = AppFullName,
                Description = AppDescription
            };

            var language = app.Argument("[language]", "The interactive programming language, defaults to csharp");
            var help = app.Option("-h|--help", "Show help information", CommandOptionType.NoValue);

            app.OnExecute(() => Run(language.Value, help.HasValue(), app.RemainingArguments));
            return app.Execute(args);
        }
开发者ID:akrisiun,项目名称:dotnet-cli,代码行数:16,代码来源:Program.cs

示例13: Main

        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "dotnet publish-iis",
                FullName = "Asp.Net Core IIS Publisher",
                Description = "IIS Publisher for the Asp.Net Core web applications",
            };
            app.HelpOption("-h|--help");

            var publishFolderOption = app.Option("-p|--publish-folder", "The path to the publish output folder", CommandOptionType.SingleValue);
            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 publishFolder = publishFolderOption.Value();
                var framework = frameworkOption.Value();

                if (publishFolder == null || framework == null)
                {
                    app.ShowHelp();
                    return 2;
                }

                Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'");

                var exitCode = new PublishIISCommand(publishFolder, framework, configurationOption.Value(), projectPath.Value).Run();

                Reporter.Output.WriteLine("Configuring project completed successfully");

                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:aspnet,项目名称:IISIntegration,代码行数:47,代码来源:Program.cs

示例14: AddCommandLineParameterTo

        internal void AddCommandLineParameterTo(CommandLineApplication command)
        {
            var isBoolProperty = Property.PropertyType == typeof(bool);
            var optionAttribute = Property.GetOptionAttribute();

            //Note: This means all bool properties are treated as options by default.
            //ArgumentAttribute on such a property is ignored.
            if (isBoolProperty || optionAttribute != null)
            {
                //This is just so that all the below code does not need to
                //check for null on attribute. Not pure but works.
                var nullSafeOptionAttribute = optionAttribute ?? new OptionAttribute();

                var template = GetOptionTemplate(nullSafeOptionAttribute);
                var optionType = isBoolProperty ? CommandOptionType.NoValue : CommandOptionType.SingleValue;

                var option = command.Option(template, nullSafeOptionAttribute.Description ?? "", optionType);

                _valueAccessor = () =>
                {
                    if (isBoolProperty)
                    {
                        return option.HasValue() ? true : (nullSafeOptionAttribute.DefaultValue ?? false);
                    }
                    else
                    {
                        return option.HasValue() ? option.Value() : (nullSafeOptionAttribute.DefaultValue ?? "");
                    }
                };
            }
            else
            {
                //And all other string properties are considered arguments by default
                //even if the ArgumentAttribute is not mentioned on them.
                var argumentAttribute = Property.GetArgumentAttribute();
                var description = argumentAttribute != null && !string.IsNullOrWhiteSpace(argumentAttribute.Description)
                    ? argumentAttribute.Description
                    : "";

                var argument = command.Argument(Property.Name, description);
                _valueAccessor = () => argument.Value;
            }
        }
开发者ID:leloulight,项目名称:Scaffolding,代码行数:43,代码来源:ParameterDescriptor.cs

示例15: Main

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

            var app = new CommandLineApplication(throwOnUnexpectedArg: false);
            app.Name = "dotnet repl csi";
            app.FullName = "C# REPL";
            app.Description = "C# REPL for the .NET platform";
            app.HelpOption("-h|--help");

            var script = app.Argument("<SCRIPT>", "The .csx file to run. Defaults to interactive mode");
            var framework = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var preserveTemporary = app.Option("-t|--preserve-temporary", "Preserve the temporary directory containing the compiled project", CommandOptionType.NoValue);
            var project = app.Option("-p|--project <PROJECT>", "The path to the project to run. Can be a path to a project.json or a project directory", CommandOptionType.SingleValue);

            app.OnExecute(() => Run(script.Value, framework.Value(), configuration.Value(), preserveTemporary.HasValue(), project.Value(), app.RemainingArguments));
            return app.Execute(args);
        }
开发者ID:alexanderkyte,项目名称:cli,代码行数:19,代码来源:Program.cs


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