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


C# CommandLine类代码示例

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


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


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