Class: Crawlscope::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/crawlscope/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out:, err:, configuration: Configuration.new, task: nil) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
16
17
18
# File 'lib/crawlscope/cli.rb', line 11

def initialize(argv, out:, err:, configuration: Configuration.new, task: nil)
  @argv = Array(argv).dup
  @out = out
  @err = err
  @configuration = configuration
  @configuration.output = out
  @task = task
end

Class Method Details

.start(argv, out: $stdout, err: $stderr, **options) ⇒ Object



7
8
9
# File 'lib/crawlscope/cli.rb', line 7

def self.start(argv, out: $stdout, err: $stderr, **options)
  new(argv, out: out, err: err, **options).call
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/crawlscope/cli.rb', line 20

def call
  command = @argv.shift.to_s

  case command
  when "help", ""
    @out.puts(general_usage)
    0
  when "validate"
    run_validate
  when "ldjson"
    run_ldjson
  when "version", "--version", "-v"
    @out.puts(Crawlscope::VERSION)
    0
  else
    @err.puts("Unknown command: #{command}")
    @err.puts("")
    @err.puts(general_usage)
    1
  end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument, ConfigurationError, ArgumentError => error
  @err.puts(error.message)
  @err.puts("")
  @err.puts(general_usage)
  1
end