Class: Musicapp::Cli

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

Instance Method Summary collapse

Instance Method Details

#fieldsObject



55
56
57
58
59
# File 'lib/musicapp/cli.rb', line 55

def fields
  Script::FULL_PROPERTIES.sort.each do |f|
    puts f
  end
end

#getObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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.(fields).each do |track|
    puts track.to_json
  end
rescue ::Musicapp::Error => e
  color_warn e.message
  exit 1
end

#nextObject



72
73
74
# File 'lib/musicapp/cli.rb', line 72

def next
  Script.next_track
end

#pauseObject



67
68
69
# File 'lib/musicapp/cli.rb', line 67

def pause
  Script.pause
end

#playObject



62
63
64
# File 'lib/musicapp/cli.rb', line 62

def play
  Script.play
end

#setObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/musicapp/cli.rb', line 27

def set
   = $stdin.read.each_line.map {|l| JSON.parse(l) }
  properties = .flat_map(&:keys).uniq.sort
   = Script.(properties | %w(name))

  .zip().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.()
  puts "Complete!"
rescue ::Musicapp::Error => e
  color_warn e.message
  exit 1
rescue ::JSON::ParserError => e
  color_warn e.message
  exit 2
end