Class: Xrandrb::Cli

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

Constant Summary collapse

COMMANDS =
["status", "on", "off", "toggle", "update"]
HELP_FLAGS =
["--help", "-h"]

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



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

def initialize(argv)
  @command = argv.shift
  @argv = argv
end

Instance Method Details

#_run(xrandr_output = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xrandrb/cli.rb', line 11

def _run(xrandr_output = nil)
  @x = Xrandrb.new(xrandr_output)

  case @command
  when nil
    status
  when *HELP_FLAGS
    help
  when *COMMANDS
    if HELP_FLAGS.include?(@argv[0])
      help(@command)
    else
      __send__(@command)
    end
  else
    STDERR.puts "Unknown command '#{@command}'."
    STDERR.puts "Available commands: #{COMMANDS.join(', ')}"
    exit(1)
  end
end