Class: Wavesync::Commands::Setlist

Inherits:
Command
  • Object
show all
Defined in:
lib/wavesync/commands/setlist.rb

Instance Method Summary collapse

Methods inherited from Command

#parse_options

Instance Method Details

#runObject

: () -> void



17
18
19
20
21
22
23
24
25
26
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
# File 'lib/wavesync/commands/setlist.rb', line 17

def run
  subcommand = ARGV.shift

  _options, config = parse_options(banner: 'Usage: wavesync setlist <subcommand> [options]')

  case subcommand
  when 'create'
    name = require_name('create')
    if Wavesync::Setlist.exists?(config.library, name)
      puts "Setlist '#{name}' already exists. Use 'wavesync setlist edit #{name}' to edit it."
      exit 1
    end
    setlist = Wavesync::Setlist.new(config.library, name)
    Wavesync::SetlistEditor.new(setlist, config.library).run
  when 'edit'
    name = require_name('edit')
    unless Wavesync::Setlist.exists?(config.library, name)
      puts "Setlist '#{name}' not found. Use 'wavesync setlist create #{name}' to create it."
      exit 1
    end
    setlist = Wavesync::Setlist.load(config.library, name)
    Wavesync::SetlistEditor.new(setlist, config.library).run
  when 'list'
    setlists = Wavesync::Setlist.all(config.library)
    if setlists.empty?
      puts 'No setlists found.'
    else
      setlists.each { |setlist| puts "#{setlist.name} (#{setlist.tracks.size} tracks)" }
    end
  else
    puts "Unknown subcommand: #{subcommand || '(none)'}"
    puts 'Available subcommands: create, edit, list'
    exit 1
  end
end