Class: EchSpec::CLI::Resolve
- Inherits:
-
Object
- Object
- EchSpec::CLI::Resolve
- Includes:
- EchConfigPrinter
- Defined in:
- lib/echspec/cli/resolve.rb
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#parse_options(argv) ⇒ Object
rubocop: disable Metrics/MethodLength.
Methods included from EchConfigPrinter
#evaluate_widths, #field_pairs, #print_ech_configs, #print_field
Instance Method Details
#execute(argv) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/echspec/cli/resolve.rb', line 5 def execute(argv) fpath, well_known, hostname = (argv) result = if !fpath.nil? Spec::Spec9.parse_pem(File.read(fpath)) elsif well_known Spec::Spec9.well_known_origin_svcb(hostname) else Spec::Spec9.resolve_ech_configs(hostname) end case result in Ok(ech_configs) print_ech_configs(ech_configs) in Err(details, _) warn "** #{details}" exit 1 end end |
#parse_options(argv) ⇒ Object
rubocop: disable Metrics/MethodLength
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/echspec/cli/resolve.rb', line 26 def (argv) op = OptionParser.new fpath = nil well_known = false op.on( '-f', '--file FILE', 'path to ECHConfigs PEM file (default resolve ECHConfigs via DNS)' ) do |v| fpath = v end op.on( '-w', '--well-known', 'resolve ECHConfigs via well-known URI, instead of DNS' ) do well_known = true end op. = " Usage: echspec resolve [OPTIONS...] [{HOSTNAME}]\n\n Resolve ECHConfigs for a hostname and print fields.\n {HOSTNAME} is required unless -f is specified.\n\n Examples:\n\n $ echspec resolve localhost\n $ echspec resolve -w localhost\n $ echspec resolve -f echconfigs.pem\n\n Options:\n USAGE\n\n begin\n args = op.parse(argv)\n rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e\n warn op\n warn \"** \#{e.message}\"\n exit 1\n end\n\n if !fpath.nil? && !File.exist?(fpath)\n warn '** {FILE} is not found'\n exit 1\n end\n\n if fpath.nil? && args.length != 1\n warn op\n warn '** {HOSTNAME} argument is not specified'\n exit 1\n end\n\n [fpath, well_known, args[0]]\nend\n" |