Class: MonoVM::Whois::CLI
- Inherits:
-
Object
- Object
- MonoVM::Whois::CLI
- Defined in:
- lib/monovm/whois/cli.rb
Overview
The monovm-whois command.
Kept as a class taking explicit +stdout+/+stderr+ and returning an exit code
rather than calling exit itself, so the specs can run it in-process and assert
on its output.
Exit codes: 0 when every name got a real answer, 1 when any came back unknown or invalid, 2 for a usage error.
Constant Summary collapse
- EXIT_OK =
0- EXIT_INCONCLUSIVE =
1- EXIT_USAGE =
2- COLOURS =
Terminal colours, skipped when output is redirected.
{ available: "\e[32m", # green registered: "\e[31m", # red premium: "\e[33m", # yellow unknown: "\e[35m", # magenta invalid: "\e[90m" # grey }.freeze
- RESET =
grey
"\e[0m"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
36 37 38 39 40 |
# File 'lib/monovm/whois/cli.rb', line 36 def initialize(stdout: $stdout, stderr: $stderr) @stdout = stdout @stderr = stderr @options = end |
Class Method Details
.run(argv, stdout: $stdout, stderr: $stderr) ⇒ Object
32 33 34 |
# File 'lib/monovm/whois/cli.rb', line 32 def self.run(argv, stdout: $stdout, stderr: $stderr) new(stdout: stdout, stderr: stderr).run(argv) end |
Instance Method Details
#run(argv) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/monovm/whois/cli.rb', line 42 def run(argv) domains = parser.parse(argv) return print_help if @options[:help] return print_version if @options[:version] return print_tld_count if @options[:tld_count] return usage_error("give at least one domain name") if domains.empty? results = check(domains) render(results) exit_code(results) rescue OptionParser::ParseError => e usage_error(e.) rescue Error => e @stderr.puts "monovm-whois: #{e.}" EXIT_INCONCLUSIVE rescue Interrupt @stderr.puts "monovm-whois: interrupted" EXIT_INCONCLUSIVE end |