ZeroInstall.Publish.Capture.CommandMapper.GetCommand C# (CSharp) Method

GetCommand() private method

private GetCommand ( [ commandLine, [ additionalArgs ) : Command
commandLine [
additionalArgs [
return Command
        public Command GetCommand([NotNull] string commandLine, [CanBeNull] out string additionalArgs)
        {
            #region Sanity checks
            if (commandLine == null) throw new ArgumentNullException(nameof(commandLine));
            #endregion

            foreach (var tuple in _commmands.Where(tuple => commandLine.StartsWithIgnoreCase(tuple.CommandLine)))
            {
                additionalArgs = commandLine.Substring(tuple.CommandLine.Length).TrimStart();
                return tuple.Command;
            }

            // No match found
            additionalArgs = null;
            return null;
        }
    }

Usage Example

コード例 #1
0
        public void TestGetCommand()
        {
            var commandNoArgs = new Command {
                Name = "no-args", Path = "entry.exe"
            };
            var commandArgs1 = new Command {
                Name = "args1", Path = "entry.exe", Arguments = { "--arg1", "long argument" }
            };
            var commandArgs2 = new Command {
                Name = "args2", Path = "entry.exe", Arguments = { "--arg2", "long argument" }
            };
            var provider = new CommandMapper("installation directory", new[] { commandNoArgs, commandArgs1, commandArgs2 });

            string additionalArgs;

            provider.GetCommand("installation directory" + Path.DirectorySeparatorChar + "entry.exe", out additionalArgs)
            .Should().BeSameAs(commandNoArgs);
            additionalArgs.Should().Be("");

            provider.GetCommand("\"installation directory" + Path.DirectorySeparatorChar + "entry.exe\" --arg1", out additionalArgs)
            .Should().BeSameAs(commandNoArgs);
            additionalArgs.Should().Be("--arg1");

            provider.GetCommand("\"installation directory" + Path.DirectorySeparatorChar + "entry.exe\" --arg1 \"long argument\" bla", out additionalArgs)
            .Should().BeSameAs(commandArgs1);
            additionalArgs.Should().Be("bla");

            provider.GetCommand("\"installation directory" + Path.DirectorySeparatorChar + "entry.exe\" --arg2 \"long argument\" bla", out additionalArgs)
            .Should().BeSameAs(commandArgs2);
            additionalArgs.Should().Be("bla");

            provider.GetCommand("Something" + Path.DirectorySeparatorChar + "else.exe", out additionalArgs)
            .Should().BeNull();
        }
All Usage Examples Of ZeroInstall.Publish.Capture.CommandMapper::GetCommand