Module: Atlasq::Shell

Defined in:
lib/atlasq/shell.rb

Constant Summary collapse

SKIP_PAGER =
%i[usage version].freeze
DEFAULT_SHELL_HEIGHT =
24

Class Method Summary collapse

Class Method Details

.start!(args = ARGV) ⇒ Object

Parameters:

  • command (Array<String>)

    line arguments



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/atlasq/shell.rb', line 8

def self.start!(args = ARGV)
  warn "DEBUG: args: #{args}" if DEBUG
  options = Command.parse(args)
  warn "DEBUG: options: #{options}" if DEBUG
  content = options.command.run(options.args)

  if content.empty?
    Atlasq.failed!
  elsif use_pager?(options, content)
    require "tty-pager"
    TTY::Pager.page(content)
  else
    puts content
  end

  exit(1) if Atlasq.failed?
end

.use_pager?(options, content) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/atlasq/shell.rb', line 31

def self.use_pager?(options, content)
  $stdout.tty? &&
    options.command.to_pager? &&
    content.count("\n") >= DEFAULT_SHELL_HEIGHT
end