#!/usr/bin/env ruby # frozen_string_literal: true # Ruby internal require 'pp' # Project internal require 'tls_map' require 'tls_map/cli' # External require 'docopt' require 'paint' doc = <<~DOCOPT TLS map Usage: tls-map search [-o --force] [--no-color --debug] tls-map export [--force] [--debug] tls-map update [--debug] tls-map -h | --help tls-map --version Search options: (offline) The type of term. Accepted values: codepoint, iana, openssl, gnutls, nss. The cipher algorithm name. -o, --output Displayed fields. Accepted values: all, codepoint, iana, openssl, gnutls, nss. [default: all] Export options: (offline) The output file name to write to. Supported formats: markdown (a markdown table), json_pretty (expanded JSON), json_compact (minified JSON), marshal (Ruby marshalized hash). Update options: (online) DANGEROUS, will break database integrity, force option will be required Other options: --force Force parsing even if intigrity check failed (DANGEROUS, may result in command execution vulnerability) --no-color Disable colorized output --debug Display arguments -h, --help Show this screen --version Show version DOCOPT begin args = Docopt.docopt(doc, version: TLSmap::VERSION) Paint.mode = 0 if args['--no-color'] pp args if args['--debug'] if args['search'] cli = TLSmap::CLI.new(args['--force']) res = cli.search(args[''].to_sym, args[''], args['--output'].to_sym) puts Paint['No match found', :red] if res.empty? res.each do |k, v| puts "#{Paint[k, :green]}: #{Paint[v, :white]}" end elsif args['export'] cli = TLSmap::CLI.new(args['--force']) cli.export(args[''], args[''].to_sym) puts "#{args['']} exported" elsif args['update'] cli = TLSmap::CLI.new cli.update puts 'Database updated' end rescue Docopt::Exit => e puts e.message end