Пример #1
0
        public void CommandTemplaterFailsIfArgumentsAreNotTemplated()
        {
            var placeholders = new CommandPlaceholders("/source.wav", "/out_dir/", "/TempDir/", "/");
            var template     = "audio2csv {source} {output} --no-debug";

            var result = runner.PrepareArguments(template, new(), placeholders);

            result.Should().Be("audio2csv /source.wav /out_dir/ --no-debug");

            var faultyTemplate = "audio2csv {source} {config} {output} --no-debug";

            Action act = () => runner.PrepareArguments(faultyTemplate, new(), placeholders);

            act.Should()
            .Throw <ArgumentException>()
            .WithMessage("Could not finish templating command. Missing a value for parameter `{config}`");
        }
Пример #2
0
        public async Task <ToolResult> Run(Tool tool, FileInfo source, Dictionary <string, object> suiteConfig, IDirectoryInfo configDirectory)
        {
            var tempDir   = temp.GetTempDir().Unwrap();
            var outputDir = tempDir;

            var placeholders = new CommandPlaceholders(source.FullName, outputDir.FullName, tempDir.FullName, configDirectory.FullName);
            var arguments    = PrepareArguments(tool.Command, suiteConfig, placeholders);

            logger.LogTrace("Running process: {tool} {args}", tool.Executable, arguments);
            ProcessResult processResult;

            using (var timer = logger.Measure("Running process"))
            {
                processResult = await ExecuteShellCommand(tool.Executable, arguments, timeout, tempDir);
            }

            var version = GetVersion(tool.VersionRegex, processResult);


            logger.LogDebug("Finished process {tool} {args} with result {exitCode}", tool.Executable, arguments, processResult.ExitCode);
            logger.LogTrace("Process detail: {@process}", processResult);

            return(new ToolResult(processResult.Success, outputDir, processResult, tool.Executable + " " + arguments, version));
        }
Пример #3
0
        public string PrepareArguments(string args, Dictionary <string, object> suiteConfig, CommandPlaceholders placeholders)
        {
            logger.LogTrace("Formatting args: {args} with parameters {@placeholders} and {@suiteConfig}", args, placeholders, suiteConfig);
            var standardPlaceholders  = TokenValueContainer.FromObject(placeholders);
            var suitePlaceholders     = TokenValueContainer.FromDictionary(suiteConfig);
            var compositePlaceholders = TokenValueContainer.Combine(
                standardPlaceholders,
                suitePlaceholders,
                ThrowOnMissingValueContainer.Instance);


            var parsedArgs    = SegmentedString.Parse(args);
            var formattedArgs = parsedArgs.Format(compositePlaceholders, formatter: tokenFormatter);

            logger.LogTrace("Formatted args: {args}", formattedArgs);
            return(formattedArgs);
        }