Class: WSDirector::CLI

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

Overview

Command line interface for WsDirector

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



31
32
33
# File 'lib/wsdirector/cli.rb', line 31

def config
  @config
end

Instance Method Details

#runObject



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
# File 'lib/wsdirector/cli.rb', line 33

def run
  @config = Configuration.new

  parse_args!

  begin
    require "colorize" if config.colorize?
  rescue LoadError
    config.colorize = false
    warn "Install colorize to use colored output"
  end

  connection_options = {
    subprotocol: config.subprotocol
  }.compact

  scenario = config.scenario_path || config.json_scenario

  config.ws_url = "ws://#{config.ws_url}" unless config.ws_url.start_with?(/wss?:\/\//)

  url = config.ws_url
  scale = config.scale
  sync_timeout = config.sync_timeout
  colorize = config.colorize

  logger = $stdout if config.verbose

  result = WSDirector.run(
    scenario,
    url:,
    connection_options:,
    scale:,
    sync_timeout:,
    logger:,
    colorize:
  )

  puts "\n\n" if config.verbose

  result.print_summary(colorize: config.colorize?)
  result.success? || exit(1)
end