Class: MM::Command::Run

Inherits:
AbstractCommand show all
Defined in:
lib/mm/cmds/run.rb

Instance Method Summary collapse

Methods inherited from AbstractCommand

#card_property?, #display_value, #options, #output, #run, #user_property?, #view

Instance Method Details

#cache_optionsObject

don’t want to cache options of this command



53
54
# File 'lib/mm/cmds/run.rb', line 53

def cache_options
end

#do_onceObject



43
44
45
46
47
48
49
50
# File 'lib/mm/cmds/run.rb', line 43

def do_once
  parse_script
  output "script      => #{options[:script]}"
  attrs = ::TransitionExecutionLanguageParser.new.parse(options[:script])
  output "attrs       => #{attrs.inspect}"
  attrs[:properties] = attrs[:properties].collect{|key, value| {:name => key, :value => value}} if attrs[:properties]
  create_transition_execution(attrs)
end

#docObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mm/cmds/run.rb', line 60

def doc
%{
usage: mm run <transition_script>

transition script grammar: 
    <transition name> #<card_number> [options]
    options: 
  1. with <properties>: properties: prop_name1 => prop_value1, prop_name2 => prop_value2
  2. (<comment>): comment: should be ok for any words except '(' and ')'

Environment variable options:
  Any variable name start with 'MM_TRANSITION_SCRIPT_TEMPLATE_' would be handled as a transition script template. The string following the prefix would be template name, e.g. MM_TRANSITION_SCRIPT_TEMPLATE_FIX means a transition script template named 'fix'. You can specify a template name to run the transition, and MingleMingle also would help you to fill options into the template by same name, e.g. MM_TRANSITION_SCRIPT_TEMPLATE_FIX='Fix #\#{number} with resolution => fixed', MingleMingle would look for option named number in the options which is get from another environment variable MM_NUMBER=102. So type in 'mm run fix' would be translated to 'Fix #102 with fixed_revision => fixed'

Synopsis:
    mm run 'complete fix #1 with revision => 100, status => open (some comment)'
    mm run fix => run template named fix, you need setup environment variable
    
Notes:
  * You can specify variable in the transition script by \#{variable name}, MingleMingle will look for variable in the environment variable. For example, set up environment variable: export MM_NUMBER=105, then transition script 'Start fix \#{number}' would be parsed as 'Start fix #105'.
}
end

#parse(argv) ⇒ Object



56
57
58
# File 'lib/mm/cmds/run.rb', line 56

def parse(argv)
  options[:script] = argv.join(' ')
end

#parse_scriptObject



38
39
40
41
# File 'lib/mm/cmds/run.rb', line 38

def parse_script
  parse_template
  parse_variables
end

#parse_templateObject



20
21
22
23
24
# File 'lib/mm/cmds/run.rb', line 20

def parse_template
  if template = options["TRANSITION_SCRIPT_TEMPLATE_#{options[:script].gsub(/ /, '_')}".downcase.to_sym]
    options[:script] = template
  end
end

#parse_variablesObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mm/cmds/run.rb', line 26

def parse_variables
  options.keys.each do |key|
    if options[:script] =~ /\{#{key}\}/
      options[:script] = if key == :number
        options[:script].gsub(/#?#\{#{key}\}/, "##{options[key]}")
      else
        options[:script].gsub(/#\{#{key}\}/, options[key])
      end
    end
  end
end