qcmd 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,13 @@ module Qcmd
4
4
  @defaults ||= {
5
5
  'n' => 'cue $1 name $2',
6
6
  # zero-out cue_number
7
- 'zero-out' => (1..48).map {|n| "(cue $1 sliderLevel #{n} 0)"}.join(' '),
7
+ 'zero-out' => '(log-silent)' +
8
+ (1..48).map {|n| "(cue $1 sliderLevel #{n} 0)"}.join(' ') +
9
+ '(log-noisy) (echo "set slider levels for cue $1 to all zeros")',
8
10
  # copy-sliders from_cue_number to_cue_number
9
- 'copy-sliders' => (1..48).map {|n| "(cue $2 sliderLevel #{n} (cue $1 sliderLevel #{n} 0))"}.join(' ')
11
+ 'copy-sliders' => '(log-silent)' +
12
+ (1..48).map {|n| "(cue $2 sliderLevel #{n} (cue $1 sliderLevel #{n}))"}.join(' ') +
13
+ '(log-noisy) (echo "copied slider levels from cue $1 to cue $2")',
10
14
  }.merge(copy_cue_actions)
11
15
  end
12
16
 
@@ -8,7 +8,7 @@ module Qcmd
8
8
  attr_accessor :prompt
9
9
 
10
10
  def self.launch options={}
11
- new options
11
+ new(options).start
12
12
  end
13
13
 
14
14
  def initialize options={}
@@ -33,8 +33,8 @@ module Qcmd
33
33
  end
34
34
 
35
35
  if options[:command_given]
36
- handle_input Qcmd::Parser.parse(options[:command])
37
- return
36
+ split_and_handle options[:command]
37
+ exit
38
38
  end
39
39
  elsif !connect_default_workspace
40
40
  Handler.print_workspace_list
@@ -45,7 +45,7 @@ module Qcmd
45
45
  # add aliases to input completer
46
46
  InputCompleter.add_commands aliases.keys
47
47
 
48
- start
48
+ self
49
49
  end
50
50
 
51
51
  def machine
@@ -85,7 +85,22 @@ module Qcmd
85
85
 
86
86
  Qcmd.debug "[CLI replace_args] found $#{ arg_idx }, replacing with #{ arg_val.inspect }"
87
87
 
88
- arg = arg.to_s.sub("$#{ arg_idx }", arg_val.to_s)
88
+ if arg == :"$#{ arg_idx }"
89
+ # pure symbol replace
90
+ # alias: [:cue, :$1, :name]
91
+ # input: [:cname, 25]
92
+ #
93
+ # result: :$1 -> 25
94
+ arg = arg_val
95
+ else
96
+ # arg replacement inside string
97
+ # alias: [:cue, :$1, :name, "hello $2"]
98
+ # input: [:cname, 25, 26]
99
+ #
100
+ # result: :$1 -> 25
101
+ # result: "hello $2" -> "hello 26"
102
+ arg = arg.to_s.sub("$#{ arg_idx }", arg_val.to_s)
103
+ end
89
104
  end
90
105
 
91
106
  arg
@@ -291,13 +306,7 @@ module Qcmd
291
306
  Qcmd::History.push(cli_input)
292
307
 
293
308
  begin
294
- if /;/ =~ cli_input
295
- cli_input.split(';').each do |sub_input|
296
- handle_input Qcmd::Parser.parse(sub_input.strip)
297
- end
298
- else
299
- handle_input Qcmd::Parser.parse(cli_input)
300
- end
309
+ split_and_handle(cli_input)
301
310
  rescue => ex
302
311
  print "Command parser couldn't handle the last command: #{ ex.message }"
303
312
  print ex.backtrace
@@ -305,9 +314,28 @@ module Qcmd
305
314
  end
306
315
  end
307
316
 
317
+ def split_and_handle cli_input
318
+ if /;/ =~ cli_input
319
+ cli_input.split(';').each do |sub_input|
320
+ handle_input Qcmd::Parser.parse(sub_input.strip)
321
+ end
322
+ else
323
+ handle_input Qcmd::Parser.parse(cli_input)
324
+ end
325
+ end
326
+
308
327
  # the actual command line interface interactor
309
328
  def handle_input args
310
- command = args[0].to_s
329
+ if args.all? {|a| a.is_a?(Array)}
330
+ # commands all the way down, just get out of the way
331
+ args.each {|arg|
332
+ Qcmd.debug "calling recursive handle_input on #{ arg.inspect }"
333
+ handle_input(arg)
334
+ }
335
+ return
336
+ else
337
+ command = args[0].to_s
338
+ end
311
339
 
312
340
  Qcmd.debug "[CLI handle_input] command: #{ command }; args: #{ args.inspect }"
313
341
 
@@ -486,7 +514,6 @@ module Qcmd
486
514
  end
487
515
 
488
516
  when 'select'
489
-
490
517
  if args.size == 2
491
518
  reply = send_workspace_command "#{ args[0] }/#{ args[1] }"
492
519
 
@@ -506,7 +533,7 @@ module Qcmd
506
533
  log(:warning, "The select command should be in the form `select CUE_NUMBER`.")
507
534
  end
508
535
 
509
- # local ruby commands
536
+ # local commands
510
537
  when 'sleep'
511
538
  if args.size != 2
512
539
  log(:warning, "The sleep command expects one argument")
@@ -515,6 +542,29 @@ module Qcmd
515
542
  else
516
543
  sleep args[1].to_f
517
544
  end
545
+
546
+ when 'log-silent'
547
+ @previous_log_level = Qcmd.log_level
548
+ Qcmd.log_level = :none
549
+
550
+ when 'log-noisy'
551
+ Qcmd.log_level = @previous_log_level || :info
552
+
553
+ when 'log-debug'
554
+ Qcmd.log_level = :debug
555
+ print "set log level to :debug"
556
+
557
+ when 'log-info'
558
+ Qcmd.log_level = :info
559
+ print "set log level to :info"
560
+
561
+ when 'echo'
562
+ if args[1].is_a?(Array)
563
+ print Action.evaluate(args[1])
564
+ else
565
+ print args[1]
566
+ end
567
+
518
568
  else
519
569
  if aliases[command]
520
570
  Qcmd.debug "[CLI handle_input] using alias #{ command }"
@@ -524,15 +574,16 @@ module Qcmd
524
574
  # alias expansion failed, go back to CLI
525
575
  return if new_expression.nil?
526
576
 
527
- Qcmd.debug "[CLI handle_input] expanded to: #{ new_expression.inspect }"
528
-
529
- # recurse!
577
+ # unpack nested command. e.g., [[:cue, 1, :name]] -> [:cue, 1, :name]
530
578
  if new_expression.size == 1 && new_expression[0].is_a?(Array)
531
579
  while new_expression.size == 1 && new_expression[0].is_a?(Array)
532
580
  new_expression = new_expression[0]
533
581
  end
534
582
  end
535
583
 
584
+ Qcmd.debug "[CLI handle_input] expanded to: #{ new_expression.inspect }"
585
+
586
+ # recurse!
536
587
  if new_expression.all? {|exp| exp.is_a?(Array)}
537
588
  new_expression.each {|nested_expression|
538
589
  handle_input nested_expression
@@ -280,6 +280,17 @@ sleep NUMBER
280
280
  > cue 3 start; sleep 2; stop
281
281
 
282
282
  Will start cue number 3, then stop it two seconds later.
283
+
284
+ log-silent, log-noisy
285
+
286
+ Turn off output, turn it back on, respectively.
287
+
288
+ log-debug, log-info
289
+
290
+ Set output "level" to debug or info, respectively. Debug will tell you
291
+ everything qcmd is doing, in great detail. It's really just for development
292
+ purposes.
293
+
283
294
  ]
284
295
  end
285
296
  end
@@ -1,5 +1,5 @@
1
1
  module Qcmd
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
 
4
4
  class << self
5
5
  def installed_version
@@ -20,10 +20,9 @@ describe Qcmd::Action do
20
20
  Qcmd.context.qlab.send(OSC::Message.new('/alwaysReply', 1))
21
21
  end
22
22
 
23
- it "should call `parse` when initialized" do
24
- Qcmd::Action.any_instance.stub(:parse) { true }
25
- Qcmd::Action.any_instance.should_receive(:parse)
26
- Qcmd::Action.new [:cue, 10, :name]
23
+ it "should parse when initialized" do
24
+ action = Qcmd::Action.new 'cue 10 name'
25
+ action.code.should eql([:cue, 10, :name])
27
26
  end
28
27
 
29
28
  it 'should send a command when evaluated' do
@@ -1,19 +1,22 @@
1
1
  require 'qcmd'
2
2
 
3
- describe Qcmd::CLI do
4
- it "should call `start` when initialized" do
5
- Qcmd::CLI.any_instance.stub(:start) { true }
6
- Qcmd::CLI.any_instance.should_receive(:start)
7
- Qcmd::CLI.new
3
+ class NonStarter
4
+ def start
8
5
  end
6
+ end
9
7
 
10
- it 'should respond to launch' do
8
+ describe Qcmd::CLI do
9
+ it 'should init on launch' do
10
+ Qcmd::CLI.stub(:new) { NonStarter.new }
11
11
  Qcmd::CLI.should_receive :new
12
12
  Qcmd::CLI.launch
13
13
  end
14
14
 
15
- describe 'handling input' do
16
- it 'should evaluate cue commands' do
15
+ describe 'replace_args' do
16
+ it 'should replace args in alias expression with values of given type' do
17
+ cli = Qcmd::CLI.new
18
+ new_command = cli.replace_args [:cue, :'$1', :name, "hello $2"], [:at, 2, 3]
19
+ new_command.should eql([:cue, 2, :name, "hello 3"])
17
20
  end
18
21
  end
19
22
  end
@@ -66,6 +66,11 @@ describe Qcmd::Parser do
66
66
  tokens.should eql([:cue, 1, :name, 'this is (not good)'])
67
67
  end
68
68
 
69
+ it 'should parse multiple commands in a row' do
70
+ tokens = Qcmd::Parser.parse '(copy-sliders 1 2) (echo "DONE!")'
71
+ tokens.should eql([[:'copy-sliders', 1, 2], [:echo, "DONE!"]])
72
+ end
73
+
69
74
  ## Generating
70
75
 
71
76
  describe "generating expressions" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 14
9
- version: 0.1.14
8
+ - 15
9
+ version: 0.1.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Bachman