Ejemplo n.º 1
0
        public void Configure(CommandLineApplication cmd)
        {
            _force = cmd.Option <bool>("-f|--force", "Forces overwrite of an existing key file.",
                                       CommandOptionType.NoValue);

            _hashAlgorithm = cmd.Option <string>(
                "--hash <HASHALG>",
                "Specifies the embedding hash algorithm. Possible values: SHA1|SHA256|SHA384|SHA512. If not specified it defaults to SHA1.",
                CommandOptionType.SingleValue);

            _hashAlgorithm
            .OnValidate(
                vc =>
            {
                if (_hashAlgorithm.HasValue() &&
                    ParseAssemblyHashAlgorithm(_hashAlgorithm.ParsedValue) == AssemblyHashAlgorithm.None)
                {
                    return(new ValidationResult($"Unknown hash algorithm '{_hashAlgorithm.ParsedValue}'."));
                }

                return(ValidationResult.Success);
            });

            _keyFile = cmd.Argument("KEYFILE", "The path of the key file.")
                       .IsRequired(false, "The 'KEYFILE' argument is required.");

            _publicKeyFile = cmd.Argument("PUBLICKEYFILE", "The path of the public key file.")
                             .IsRequired(false, "The 'PUBLICKEYFILE' argument is required.");
        }
Ejemplo n.º 2
0
        public OutputArgument(CommandLineApplication app)
        {
            _formats = new HashSet <string>();
            _option  = app.Option("-o|--output", $"Specify the output format", CommandOptionType.SingleValue);
            _option.OnValidate((context) =>
            {
                var value = _option.Value();
                if (value == null || _formats.Contains(value))
                {
                    return(ValidationResult.Success);
                }

                throw new ValidationException($"The format {value} is not supported by the command!");
            });
        }