class Musicapp::Cli

Public Instance Methods

fields() click to toggle source
# File lib/musicapp/cli.rb, line 55
def fields
  Script::FULL_PROPERTIES.sort.each do |f|
    puts f
  end
end
get() click to toggle source
# File lib/musicapp/cli.rb, line 8
def get
  fields = case options[:field]
  when "all"
    :all
  when nil
    :default
  else
    options[:field].split(",")
  end

  Script.get_metadata(fields).each do |track|
    puts track.to_json
  end
rescue ::Musicapp::Error => e
  color_warn e.message
  exit 1
end
next() click to toggle source
# File lib/musicapp/cli.rb, line 72
def next
  Script.next_track
end
pause() click to toggle source
# File lib/musicapp/cli.rb, line 67
def pause
  Script.pause
end
play() click to toggle source
# File lib/musicapp/cli.rb, line 62
def play
  Script.play
end
set() click to toggle source
# File lib/musicapp/cli.rb, line 27
def set
  new_metadata = $stdin.read.each_line.map {|l| JSON.parse(l) }
  properties = new_metadata.flat_map(&:keys).uniq.sort
  current_metadata = Script.get_metadata(properties | %w(name))

  current_metadata.zip(new_metadata).each do |(current_value, new_value)|
    puts current_value["name"]
    new_value.each do |k, v|
      puts "  #{k}:"
      puts "     #{current_value[k]}"
      puts "  -> #{v}"
    end
  end

  print "Update?: "
  exit 1 unless $stdin.gets.chomp =~ /^y(es)?/i

  Script.set_metadata(new_metadata)
  puts "Complete!"
rescue ::Musicapp::Error => e
  color_warn e.message
  exit 1
rescue ::JSON::ParserError => e
  color_warn e.message
  exit 2
end

Private Instance Methods

color_warn(message) click to toggle source
# File lib/musicapp/cli.rb, line 77
def color_warn(message)
  pastel = Pastel.new
  message = pastel.red(message) if pastel.enabled?
  warn message
end