Class: TemplateBuilder::App::Add

Inherits:
Command
  • Object
show all
Defined in:
lib/template_builder/app/command_add.rb

Instance Attribute Summary

Attributes inherited from Command

#config, #stderr, #stdout

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#ask_for, #force, inherited, #initialize, #name, #priority, #run_framework, #special_case_data_mapper, standard_options, #standard_options, #standard_parameters, standard_parameters, #verbose?

Constructor Details

This class inherits a constructor from TemplateBuilder::App::Command

Class Method Details

.initialize_addObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/template_builder/app/command_add.rb', line 3

def self.initialize_add
  synopsis 'template_builder add [framework] [plugin]'

  summary 'Add new available framework or plugin at your template_builder .'

  description <<-__
Add new framework (plugin) at your template_builder gem. You can add a new framework
type and new plugin for this framework.
  __
   
   option(standard_options[:force])
   option(standard_options[:verbose])
end

Instance Method Details

#ask_for_priorityObject



73
74
75
76
77
# File 'lib/template_builder/app/command_add.rb', line 73

def ask_for_priority
  puts "Choose the priority of your framework ? (1 <=> hight et 5 <=> less)"
  answer = STDIN.gets until (1..5).include? answer.to_i
  answer
end

#build_new_gemObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/template_builder/app/command_add.rb', line 59

def build_new_gem
   puts "gem name = "    
   msg = "\t"+STDIN.gets
   puts "gem version = "
   msg += "\t\tversion : "+STDIN.gets
   puts "gem source = "
   msg += "\t\tsource : "+STDIN.gets
   puts "gem action = "
   msg += "\t\taction : "+STDIN.gets
   puts "gem command = "
   msg += "\t\tcommand : "+STDIN.gets
   msg
end

#create_framework(name) ⇒ Object



38
39
40
41
# File 'lib/template_builder/app/command_add.rb', line 38

def create_framework(name)
  priority = ask_for_priority
  ConfWriter.write_new_framework name, priority
end

#create_plugin(framework_name, plugin_name) ⇒ Object

Raises:

  • (Exception)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/template_builder/app/command_add.rb', line 43

def create_plugin(framework_name,plugin_name)
  raise Exception, "Framework #{name} doesn't exists." unless test ?e, TemplateBuilder::PATH+"/conf/"+framework_name+".yml"
  write = "\n#{plugin_name} :\n"
  answer = "Would you add a gem at your plugin? (y/yes)"
  puts answer
  while ["y\n","yes\n"].include? STDIN.gets
    write += build_new_gem 
    puts answer
  end
  puts "plugin command  ="
  write += "\tcommand :"+STDIN.gets
  puts "plugin action  ="
  write += "\taction :["+STDIN.gets+"]"
  ConfWriter.write_new_plugin framework_name, write
end

#parse(args) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/template_builder/app/command_add.rb', line 28

def parse( args )
  opts = super args
  config[:name] = args.empty? ? nil : args.join('_')
  if name.nil?
    stdout.puts opts
    exit 1
  end
  @param =  args
end

#runObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/template_builder/app/command_add.rb', line 17

def run
 case @param.length
 when 1
   create_framework @param.shift
 when 2
   create_plugin @param.shift, @param.shift
 else
   Raise Exception, "Bad number of argument, see -h for more information"
 end
end