Пример #1
0
        /// <summary>
        /// Updates the configuration with the specified parsed argument.
        /// </summary>
        private void UpdateConfigurationsWithParsedArgument(Command command, ArgumentResult result)
        {
            switch (result.Argument.Name)
            {
            case "path":
                if (command.Name is "test" || command.Name is "replay")
                {
                    // In the case of 'coyote test' or 'replay', the path is the assembly to be tested.
                    string path = Path.GetFullPath(result.GetValueOrDefault <string>());
                    this.Configuration.AssemblyToBeAnalyzed = path;
                }
                else if (command.Name is "rewrite")
                {
                    // In the case of 'coyote rewrite', the path is the JSON this.Configuration file
                    // with the binary rewriting options.
                    string filename = result.GetValueOrDefault <string>();
                    if (Directory.Exists(filename))
                    {
                        // Then we want to rewrite a whole folder full of assemblies.
                        var assembliesDir = Path.GetFullPath(filename);
                        this.RewritingOptions.AssembliesDirectory = assembliesDir;
                        this.RewritingOptions.OutputDirectory     = assembliesDir;
                    }
                    else
                    {
                        string extension = Path.GetExtension(filename);
                        if (string.Compare(extension, ".json", StringComparison.OrdinalIgnoreCase) is 0)
                        {
                            // Parse the rewriting options from the JSON file.
                            RewritingOptions.ParseFromJSON(this.RewritingOptions, filename);
                        }
                        else if (string.Compare(extension, ".dll", StringComparison.OrdinalIgnoreCase) is 0 ||
                                 string.Compare(extension, ".exe", StringComparison.OrdinalIgnoreCase) is 0)
                        {
                            this.Configuration.AssemblyToBeAnalyzed = filename;
                            var fullPath      = Path.GetFullPath(filename);
                            var assembliesDir = Path.GetDirectoryName(fullPath);
                            this.RewritingOptions.AssembliesDirectory = assembliesDir;
                            this.RewritingOptions.OutputDirectory     = assembliesDir;
                            this.RewritingOptions.AssemblyPaths.Add(fullPath);
                        }
                    }
                }

                break;
Пример #2
0
 internal static Token Token(this SymbolResult symbolResult)
 {
     return(symbolResult switch
     {
         CommandResult commandResult => commandResult.Token,
         OptionResult optionResult => optionResult.Token ??
         new Token($"--{optionResult.Option.Name}", TokenType.Option),
         ArgumentResult argResult => new Token(argResult.GetValueOrDefault <string>(), TokenType.Argument),
         _ => null
     });
Пример #3
0
        /// <summary>
        /// Validates that the specified argument result is found and has an expected file extension.
        /// </summary>
        private static void ValidateArgumentValueIsExpectedFile(ArgumentResult result, params string[] extensions)
        {
            string fileName       = result.GetValueOrDefault <string>();
            string foundExtension = Path.GetExtension(fileName);

            if (!extensions.Any(extension => extension == foundExtension))
            {
                if (extensions.Length is 1)
                {
                    result.ErrorMessage = $"File '{fileName}' does not have the expected '{extensions[0]}' extension.";
                }
                else
                {
                    result.ErrorMessage = $"File '{fileName}' does not have one of the expected extensions: " +
                                          $"{string.Join(", ", extensions)}.";
                }
            }
            else if (!File.Exists(fileName))
            {
                result.ErrorMessage = $"File '{fileName}' does not exist.";
            }
        }
 public static object GetValueOrDefault(this ArgumentResult argumentResult) =>
 argumentResult.GetValueOrDefault <object>();