Class: OsCtl::Cli::Top::Main

Inherits:
Command
  • Object
show all
Defined in:
lib/osctl/cli/top/main.rb

Instance Method Summary collapse

Methods inherited from Command

#cli_opt, #format_output, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, run

Instance Method Details

#start ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osctl/cli/top/main.rb', line 5

def start
  validate_rate

  model = Top::Model.new(
    enable_netif: opts.fetch(:netif, true),
    enable_zfs: opts.fetch(:zfs, true),
    enable_iostat: opts.fetch(:iostat, true)
  )
  model.setup

  kwargs = {}

  if gopts[:json]
    klass = Top::JsonExporter

  else
    klass = Top::Tui
    kwargs = { enable_procs: opts[:processes] }
  end

  view = klass.new(model, opts[:rate], **kwargs)
  view.start
end

#validate_rate ⇒ Object (protected)

Raises:

  • (GLI::BadCommandLine)


31
32
33
34
35
36
# File 'lib/osctl/cli/top/main.rb', line 31

def validate_rate
  rate = opts[:rate]
  return if rate && rate > 0 && rate.finite?

  raise GLI::BadCommandLine, 'rate must be a positive finite number'
end