Module: Anyplayer::CommandLine

Extended by:
CommandLine
Included in:
CommandLine
Defined in:
lib/anyplayer/command_line.rb

Constant Summary collapse

COMMANDS =
%w(
  playpause
  play
  pause
  next
  prev
  voldown
  volup
  volume
  track
  artist
  album
  vote
  name
  launched
  paused
  playing
)

Instance Method Summary collapse

Instance Method Details

#parse(argv) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/anyplayer/command_line.rb', line 26

def parse(argv)
  # Create a selector
  selector = Anyplayer::Selector.new
  if argv.first == "-v"
    selector.verbose = true
    argv.shift

    $stderr.puts "anyplayer v#{Anyplayer::VERSION}"
  end

  # Find the current player
  player = selector.player
  abort "Error: no player connected.\n" + selector.errors.join("\n") if !player

  # Call a command
  if argv.empty?
    usage(player)
  else
    command(player, argv.first)
  end
end