Class: Spx::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.shared_optionsObject



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

def shared_options
  method_option :sonic_pi_log, aliases: "-l", desc: "Log file to parse port number and token",
                               default: "~/.sonic-pi/log/spider.log"
  method_option :callback_port, aliases: "-p", desc: "UDP port to receive messages from Sonic Pi", default: "3333"
end

Instance Method Details

#play(file) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/spx/cli.rb', line 23

def play(file)
  unless runner.test_connection
    say "Cannot connect to Sonic Pi"
    return false
  end

  runner.play(File.read(file))
end

#record(file) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/spx/cli.rb', line 35

def record(file)
  unless runner.test_connection
    say "Cannot connect to Sonic Pi"
    return false
  end

  runner.record(
    File.read(file),
    File.expand_path(options[:output])
  )
end

#test_connectionObject



15
16
17
18
19
# File 'lib/spx/cli.rb', line 15

def test_connection
  runner.test_connection.tap do |connected|
    say connected ? "OK" : "NG"
  end
end

#versionObject



48
49
50
# File 'lib/spx/cli.rb', line 48

def version
  say Spx::VERSION
end