本文整理汇总了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;
}
示例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;
}
示例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();
}
示例4: PythonCompletionData
public PythonCompletionData(string text, string stub, CommandLine commandLine, bool isInstance)
{
this.Text = text;
this.Stub = stub;
this.commandLine = commandLine;
this.IsInstance = isInstance;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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.");
}
示例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;
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}