• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CommandLine类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CommandLine的典型用法代码示例。如果您正苦于以下问题:C# CommandLine类的具体用法?C# CommandLine怎么用?C# CommandLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CommandLine类属于命名空间,在下文中一共展示了CommandLine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TryParseArguments

        /// <summary>
        /// Parses the command-line.
        /// </summary>
        /// <param name="args">Arguments from command-line.</param>
        /// <param name="commandLine">Command line object created from command-line arguments</param>
        /// <returns>True if command-line is parsed, false if a failure was occurred.</returns>
        public static bool TryParseArguments(string[] args, out CommandLine commandLine)
        {
            bool success = true;

            commandLine = new CommandLine();

            for (int i = 0; i < args.Length; ++i)
            {
                if ('-' == args[i][0] || '/' == args[i][0])
                {
                    string arg = args[i].Substring(1).ToLowerInvariant();
                    if ("?" == arg || "help" == arg)
                    {
                        return false;
                    }
                    else if ("o" == arg || "out" == arg)
                    {
                        ++i;
                        if (args.Length == i)
                        {
                            Console.Error.WriteLine(String.Format("Missing file specification for '-out' option."));
                            success = false;
                        }
                        else
                        {
                            string outputPath = Path.GetFullPath(args[i]);
                            commandLine.OutputFolder = outputPath;
                        }
                    }
                }
                else
                {
                    string[] file = args[i].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    string sourcePath = Path.GetFullPath(file[0]);
                    if (!System.IO.File.Exists(sourcePath))
                    {
                        Console.Error.WriteLine(String.Format("Source file '{0}' could not be found.", sourcePath));
                        success = false;
                    }
                    else
                    {
                        commandLine.Files.Add(sourcePath);
                    }
                }
            }

            if (0 == commandLine.Files.Count)
            {
                Console.Error.WriteLine(String.Format("No inputs specified. Specify at least one file."));
                success = false;
            }

            if (String.IsNullOrEmpty(commandLine.OutputFolder))
            {
                Console.Error.WriteLine(String.Format("Ouput folder was not specified. Specify an output folder using the '-out' switch."));
                success = false;
            }

            return success;
        }
开发者ID:zooba,项目名称:wix3,代码行数:66,代码来源:CommandLine.cs


示例2: CommandExecutorContext

		public CommandExecutorContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter) : base(executor, null, commandNode, parameter)
		{
			if(commandLine == null)
				throw new ArgumentNullException("commandLine");

			_commandLine = commandLine;
		}
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:7,代码来源:CommandExecutorContext.cs


示例3: Main

 static void Main(string[] args)
 {
     Console.Title = "Irony Console Sample";
       Console.WriteLine("Irony Console Sample.");
       Console.WriteLine("");
       Console.WriteLine("Select a grammar to load:");
       Console.WriteLine("  1. Expression Evaluator");
       Console.WriteLine("  2. mini-Python");
       Console.WriteLine("  Or press any other key to exit.");
       Console.WriteLine("");
       Console.Write("?");
       var choice = Console.ReadLine();
       Grammar grammar;
       switch (choice) {
     case "1":
       grammar = new ExpressionEvaluatorGrammar();
       break;
     case "2":
       grammar = new MiniPython.MiniPythonGrammar();
       break;
     default:
       return;
       }
       Console.Clear();
       var commandLine = new CommandLine(grammar);
       commandLine.Run();
 }
开发者ID:cubean,项目名称:CG,代码行数:27,代码来源:Program.cs


示例4: PythonCompletionData

 public PythonCompletionData(string text, string stub, CommandLine commandLine, bool isInstance)
 {
     this.Text = text;
     this.Stub = stub;
     this.commandLine = commandLine;
     this.IsInstance = isInstance;
 }
开发者ID:goutkannan,项目名称:ironlab,代码行数:7,代码来源:PythonCompletionData.cs


示例5: Then_options_should_be_set_if_provided

        public void Then_options_should_be_set_if_provided()
        {
            var commandLine = new CommandLine("exe -opt1:value1 -opt4 -opt2:\"value2\"");

            Assert.AreEqual("value1", commandLine.Option1);
            Assert.AreEqual("value2", commandLine.Option2);
        }
开发者ID:kredinor,项目名称:Artifacts,代码行数:7,代码来源:When_parsing_string_options.cs


示例6: Then_options_should_be_set_if_provided

        public void Then_options_should_be_set_if_provided()
        {
            var commandLine = new CommandLine("exe -opt1:two -opt4 -opt2:\"bbb\"");

            Assert.AreEqual(Enum1.two, commandLine.Option1);
            Assert.AreEqual(Enum2.bbb, commandLine.Option2);
        }
开发者ID:kredinor,项目名称:Artifacts,代码行数:7,代码来源:When_parsing_enum_options.cs


示例7: DefaultProvider_EmptyCommandLine_Throws

 public void DefaultProvider_EmptyCommandLine_Throws()
 {
     var provider = Provider.Default;
     var commandLine = new CommandLine();
     var connectionString = new ConnectionString();
     var result = ConnectionStringBuilder.GetConnectionString(provider, commandLine, connectionString);
 }
开发者ID:jhgbrt,项目名称:SqlConsole,代码行数:7,代码来源:ConnectionStringBuilderTests.cs


示例8: CreateConsole

		/// <remarks>
		/// After the engine is created the standard output is replaced with our custom Stream class so we
		/// can redirect the stdout to the text editor window.
		/// This can be done in this method since the Runtime object will have been created before this method
		/// is called.
		/// </remarks>
		protected override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options)
		{
			ScriptingConsoleOutputStream stream = pythonConsole.CreateOutputStream();
			SetOutput(stream);
			pythonConsole.CommandLine = commandLine;
			return pythonConsole;
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:13,代码来源:PythonConsoleHost.cs


示例9: AutoLoadWithQuotes

 public void AutoLoadWithQuotes()
 {
     CommandLine commandLine = new CommandLine();
     Parser parser = new Parser("DummyProgram.exe /SourceDir:\"c:\\Program Files\"", commandLine);
     parser.Parse();
     Assert.AreEqual("c:\\Program Files", commandLine.SourceDirectory, "The source parameter is not correct.");
 }
开发者ID:AArnott,项目名称:dasblog,代码行数:7,代码来源:ParserTest.cs


示例10: Main

 static void Main(string[] args)
 {
     var commandLine = new CommandLine(args);
     if (commandLine.Help)
     {
         commandLine.ShowHelp(Console.Out);
         Environment.ExitCode = 1;
         return;
     }
     if (commandLine.HasErrors)
     {
         commandLine.ShowErrors(Console.Error);
         Environment.ExitCode = 1;
         return;
     }
     try
     {
         if (SolutionFile.IsSolutionFileName(commandLine.ProjectFile))
         {
             ProcessSolutionFile(commandLine);
         }
         else
         {
             ProcessProjectFile(commandLine);
         }
         Log.Info("Done");
     }
     catch (Exception ex)
     {
         Log.Error("Unexpected exception: " + ex.Message);
         Environment.ExitCode = 1;
     }
 }
开发者ID:jjeffery,项目名称:VProj,代码行数:33,代码来源:Program.cs


示例11: Execute

        public void Execute(Session session, CommandLine line)
        {
            session.WriteLine("usage:");
            session.WriteLine("  <command> [patameters ...]");
            session.WriteLine();

            session.WriteLine("commands:");

            var mapper = session.GetCommandMapper(line);
            if (mapper == null)
            {
                foreach (var m in session.Engine.MapperManager.GetCommandMappers())
                {
                    this.HelpFor(m, session, line);
                }
            }
            else
            {
                this.HelpFor(mapper, session, line);
                var parameterFormater = session.Engine.GetCommandMember(z => z.ParametersFormater);
                var ParameterParser = session.Engine.GetCommandMember(z => z.CommandParameterParser);
                session.WriteLine();
                session.WriteLine("parameters:");
                foreach (var formatedString in parameterFormater.Format(mapper, mapper.ExecutorBuilder.Mappers, ParameterParser))
                {
                    session.WriteLine("  " + formatedString);
                }
            }
        }
开发者ID:Cologler,项目名称:Jasily.Framework.ConsoleEngine,代码行数:29,代码来源:HelpCommand.cs


示例12: CreateProcess

 public IUpdateProcess CreateProcess(CommandLine cmdline)
 {
     Version ver;
     var version = cmdline["version"];
     if(string.IsNullOrEmpty(version))
     {
         ver = new Version(0, 0, 0, 0);
     }
     else
     {
         if(!Version.TryParse(version, out ver))
         {
             ver = new Version(0, 0, 0, 0);
         }
     }
     var git = cmdline["git"];
     if(string.IsNullOrEmpty(git))
     {
         git = DetectGitExePath();
         if(string.IsNullOrEmpty(git)) return null;
     }
     var url = cmdline["url"];
     if(string.IsNullOrEmpty(url)) return null;
     var target = cmdline["target"];
     if(string.IsNullOrEmpty(target)) return null;
     bool skipVersionCheck = cmdline.IsDefined("skipversioncheck");
     return new UpdateFromGitRepositoryProcess(ver, git, url, target, skipVersionCheck);
 }
开发者ID:Kuzq,项目名称:gitter,代码行数:28,代码来源:GitUpdateDriver.cs


示例13: Execute

        private void Execute(CommandMapper mapper, CommandLine command)
        {
            var obj = mapper.CommandClassBuilder.Build();
            var executor = mapper.ExecutorBuilder.CreateExecutor(obj);
            foreach (var kvp in command.Parameters)
            {
                var r = executor.SetParameter(kvp.Key, kvp.Value, this.Engine.MapperManager.GetAgent());
                if (r.HasError)
                {
                    this.WriteLine(r);
                    return;
                }
            }
            var missing = executor.GetMissingParameters().ToArray();
            if (missing.Length != 0)
            {
                this.Engine.GetCommandMember(z => z.MissingParametersFormater)
                    .Format(this.Engine.GetCommandMember(z => z.Output), mapper, missing,
                        this.Engine.GetCommandMember(z => z.CommandParameterParser));
                this.Help(command);
                return;
            }

            executor.Execute(this, command);
        }
开发者ID:gitter-badger,项目名称:Jasily.Framework.ConsoleEngine,代码行数:25,代码来源:Session.cs


示例14: Main

        static int Main( string[] args )
        {
            CommandLine     commandLine = new CommandLine();
            int             returnVal = 0;

            try
            {
                commandLine.Parse( args );

                if( commandLine.Mode == SyncAppMode.RunEngine )
                {
                    RunSyncEngine( commandLine );
                }
                else if( commandLine.Mode == SyncAppMode.CreateConfigTemplate )
                {
                    CreateConfigTemplateFile( commandLine );
                }
            }
            catch( Exception e )
            {
                Console.Error.WriteLine( "Error: {0}", e.ToString() );
                returnVal = -1;
            }

            if( commandLine.PauseOnExit )
            {
                Console.WriteLine();
                Console.WriteLine( "Press any key to exit..." );
                Console.ReadKey( true );
            }

            return returnVal;
        }
开发者ID:dxm007,项目名称:TrackerSync,代码行数:33,代码来源:Program.cs


示例15: WithValidOption__GetOtherOption__ReturnNull

 public void WithValidOption__GetOtherOption__ReturnNull()
 {
     string[] arguments = { "/keyfile:file" };
     var commandLine = new CommandLine(arguments);
     var option = commandLine.Option("union");
     Assert.IsNull(option);
 }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:7,代码来源:CommandLineTests.cs


示例16: Then_options_should_be_set_if_provided

        public void Then_options_should_be_set_if_provided()
        {
            var commandLine = new CommandLine("exe -opt1:12 -opt4 -opt2:\"13\"");

            Assert.AreEqual(12, commandLine.Option1);
            Assert.AreEqual(13, commandLine.Option2);
        }
开发者ID:kredinor,项目名称:Artifacts,代码行数:7,代码来源:When_parsing_int_options.cs


示例17: WithEmptyOption__GetOption__ReturnEmptyString

 public void WithEmptyOption__GetOption__ReturnEmptyString()
 {
     string[] arguments = { "/" };
     var commandLine = new CommandLine(arguments);
     var option = commandLine.Option("");
     Assert.IsEmpty(option);
 }
开发者ID:jinjingcai2014,项目名称:il-repack,代码行数:7,代码来源:CommandLineTests.cs


示例18: RunCommand

 public static void RunCommand(string[] inputArgs, CommandStatusWriter consoleOut)
 {
     using (CommandLine cmd = new CommandLine(consoleOut))
     {
         cmd.Run(inputArgs);
     }
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:7,代码来源:Program.cs


示例19: DllMain

		/// <summary>
		/// This is the entry point into the DLL.  It parses the command line and
		/// delegates the work out to each program.
		/// </summary>
		/// <param name="commandLine">The commandline that invoked the program.  Usually
		/// this corresponds to System.Environment.CommandLine</param>
		/// <returns></returns>
		public static void DllMain(string commandLine)
		{
			CommandLine = new CommandLine();
			Parser parser = new Parser(commandLine, CommandLine);			
			parser.Parse();

			if(CommandLine.Help)
			{
				Console.WriteLine("This program is used to import blog data from other blogging programs.");
				Console.WriteLine("  Note that this program will modify your content directory so back it up.");
				Console.WriteLine("  Also, the program will require an internet connection in some instances, ");
				Console.WriteLine("  like importing comments from an external server.");
				Console.WriteLine( parser.GetHelpText() );
			}
			else
			{
				switch(CommandLine.Source)
				{
					case BlogSourceType.Radio:
						if(CommandLine.SourceDirectory !=  null && CommandLine.SourceDirectory.Length > 0
							&& CommandLine.ContentDirectory != null && CommandLine.ContentDirectory.Length > 0)
						{
							Console.WriteLine("Importing entries from Radio...");
							DasBlog.Import.Radio.EntryImporter.Import(
								CommandLine.SourceDirectory,
								CommandLine.ContentDirectory);
						}
						else
						{
							Console.WriteLine("Entries from Radio not imported because either source directory or content directory were not specified.");
						}
						
						if(CommandLine.UserID != null && CommandLine.UserID.Length > 0 
							&& CommandLine.ContentDirectory != null && CommandLine.ContentDirectory.Length > 0)

						{
							if(CommandLine.CommentServer != null && CommandLine.CommentServer.Length > 0)
							{
								Console.WriteLine("Defaulting to comment server {0}.  You may need to check your radio source.  radiocomments2, etc",DasBlog.Import.Radio.CommentImporter.DefaultCommentServer);
							}

							Console.WriteLine("BETA: Importing comments from Radio...");
							DasBlog.Import.Radio.CommentImporter.Import(
								CommandLine.UserID, CommandLine.ContentDirectory, CommandLine.CommentServer );
						}
						else
						{
							Console.WriteLine("Comments from Radio not imported because comment server, userid or content directory were not specified.");
						}


						break;
					case BlogSourceType.none:
						goto default;
					default:
						throw new ApplicationException(
							string.Format("The source option was not specified or else was invalid."));
				}
			}
		}
开发者ID:plntxt,项目名称:dasblog,代码行数:67,代码来源:EntryPoint.cs


示例20: Load

        public static CommandLine Load(ICollection<string> args)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var info = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
            Console.WriteLine(Resources.Splash, info);
            if (null == args)
            {
                return new CommandLine();
            }

            var result = new CommandLine(args);
            if (!result.Help)
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine(Resources.Usage);
                Console.WriteLine(string.Empty);
                Console.WriteLine(Resources.UsageDetails);
                Console.WriteLine(string.Empty);
                Console.WriteLine(Resources.Parameters);
                Console.WriteLine(string.Empty);
                Console.WriteLine(Resources.ParametersHelp);
                Console.WriteLine(Resources.ParametersInfo);
                Console.WriteLine(string.Empty);
                Console.WriteLine(Resources.HelpLink);
            }

            return result;
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:28,代码来源:CommandLine.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CommandLine.Parser类代码示例发布时间:2022-05-24
下一篇:
C# CommandInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap