Class: OsCtl::Cli::Ps::Main

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

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods inherited from Command

#cli_opt, #format_output, #initialize, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, #require_args!, run

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

This class inherits a constructor from OsCtl::Cli::Command

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/osctl/cli/ps/main.rb', line 5

def run
  if opts[:list]
    puts Ps::Columns::COLS.join("\n")
    return
  end

  require_args!('id')

  if args[0].index(':')
    pool, id = args[0].split(':')
  else
    pool = gopts[:pool]
    id = args[0]
  end

  pl = OsCtl::Lib::ProcessList.new do |p|
    ctid = p.ct_id

    if ctid.nil? || (pool && ctid[0] != pool) || (ctid[1] != id)
      false
    else
      true
    end
  end

  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : Ps::Columns::DEFAULT
  out_cols, out_data = Ps::Columns.generate(pl, cols, gopts[:parsable])

  OutputFormatter.print(
    out_data,
    out_cols,
    layout: :columns,
    header: opts['hide-header'] ? false : true,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym),
  )
end