Class: Saruman::CLI

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

Instance Method Summary collapse

Instance Method Details

#controllerObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/saruman/cli.rb', line 154

def controller
  options = Hash.new
  options[:command] = __method__
  options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
  options[:controller_front_name] = ask("Enter Front Name of controller (will match www.yourmagentoinstall.com/frontname)") { |q| q.default = "extension_name" }
  
  options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
        
  if(options[:controllers]).nil?
    options[:controllers] = Array.new
  end
  
  begin
    question = Saruman::ControllerBuilder.new(options)
    options[:controllers] << question.output
  end while agree("Create another Controller?")

  Saruman::Generators::Controller.start([options])
  
end

#extensionObject



9
10
11
12
13
14
15
16
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/saruman/cli.rb', line 9

def extension
  options = Hash.new
  options[:command] = __method__
  options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
  options[:author] = ask("Author of extension:") { |q| q.default = "Jason Ayre www.bravenewwebdesign.com" }
  options[:version] = ask("Version number (Format - 0.0.1):") { |q| q.default = "0.0.1" }
  options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
        
  say("Would you like to create a controller?")
  choose do |menu|
    menu.choice(:yes) { options[:controller] = true }
    menu.choice(:no) { options[:controller] = false }
  end

  if(options[:controller])
    
    options[:controller_front_name] = ask("Enter Front Name of controller (will match www.yourmagentoinstall.com/frontname)") { |q| q.default = "extension_name" }
    
    if(options[:controllers]).nil?
      options[:controllers] = Array.new
    end
    
    begin
      question = Saruman::ControllerBuilder.new(options)
      options[:controllers] << question.output
    end while agree("Create another controller?")
    
  end
  
  say("Would you like to create an observer?")
  choose do |menu|
    menu.choice(:yes) { options[:observer] = true }
    menu.choice(:no) { options[:observer] = false }
  end
  
  if(options[:observer])
    
    say("Choose the events you would like to observe")
    begin
      
      choose do |menu|
        if(options[:observer_events]).nil?
          options[:observer_events] = Array.new
        end
        if @observer_menu_builder.nil?
          @observer_menu_builder = Saruman::ObserverMenuBuilder.new(menu)
        else
          @observer_menu_builder.display_choices(menu)
        end
        
      end
    end while agree("Observe another event?")
    
    options[:observer_events] = @observer_menu_builder.decisions
    
  end
  
  say("Would you like to create a model?")
  choose do |menu|
    menu.choice(:yes) { options[:model] = true }
    menu.choice(:no) { options[:model] = false }
  end
  
  if(options[:model])
    
    if(options[:models]).nil?
      options[:models] = Array.new
    end
    
    begin
      question = Saruman::ModelBuilder.new(options)
      options[:models] << question.output
    end while agree("Create another model?")
    
  end
  
  say("Would you like to create a helper?")
  choose do |menu|
    menu.choice(:yes) { options[:helper] = true }
    menu.choice(:no) { options[:helper] = false }
  end
  
  Saruman::Generators::Extension.start([options])
  
  if options[:model]
    Saruman::Generators::Model.start([options])
  end
  
  if options[:controller]
    Saruman::Generators::Controller.start([options])
  end        
  
end

#modelObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/saruman/cli.rb', line 105

def model
  options = Hash.new
  options[:command] = __method__
  options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
  options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
  if(options[:models]).nil?
    options[:models] = Array.new
  end
  
  begin
    question = Saruman::ModelBuilder.new(options)
    options[:models] << question.output
  end while agree("Create another model?")

  Saruman::Generators::Model.start([options])
  
end

#observerObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/saruman/cli.rb', line 125

def observer
  options = Hash.new
  options[:command] = __method__
  options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
  
  say("Choose the events you would like to observe")
  begin
    
    choose do |menu|
      if(options[:observer_events]).nil?
        options[:observer_events] = Array.new
      end
      if @observer_menu_builder.nil?
        @observer_menu_builder = Saruman::ObserverMenuBuilder.new(menu)
      else
        @observer_menu_builder.display_choices(menu)
      end
      
    end
  end while agree("Observe another event?")
  
  options[:observer_events] = @observer_menu_builder.decisions

  Saruman::Generators::Observer.start([options])
  
end