Module: Origen::CodeGenerators

Defined in:
lib/origen/code_generators.rb,
lib/origen/code_generators/base.rb,
lib/origen/code_generators/rake.rb,
lib/origen/code_generators/rspec.rb,
lib/origen/code_generators/semver.rb,
lib/origen/code_generators/actions.rb,
lib/origen/code_generators/bundler.rb,
lib/origen/code_generators/timever.rb,
lib/origen/code_generators/gem_setup.rb

Defined Under Namespace

Modules: Actions Classes: Base, Bundler, Error, GemSetup, RSpec, Rake, Semver, Timever

Class Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/origen/code_generators.rb', line 50

def self.find_by_name(name)
  names = name.split(':')
  case names.size
  when 1
    gen = origen_generators[names.first]
    return gen if gen
  when 2
    if names.first == 'origen'
      gen = origen_generators[names.first]
    else
      gen = plugin_generators[names.first][names.last]
    end
    return gen if gen
  end
  puts "Couldn't find a feature generator named: #{name}"
  puts
  puts 'This is the list of available features:'
  puts
  print_generators
  puts
end

.help(command = 'add') ⇒ Object

Show help message with available generators.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/origen/code_generators.rb', line 73

def self.help(command = 'add')
  puts <<-END
Add pre-built features and code snippets.

This command will add pre-built code to your application to implement a given feature. In some
cases this will be a complete feature and in others it will provide a starting point for you
to further customize.

END
  puts "Usage: origen #{command} FEATURE [args] [options]"
  puts
  puts 'General options:'
  puts "  -h, [--help]     # Print feature's options and usage"
  puts '  -p, [--pretend]  # Run but do not make any changes'
  puts '  -f, [--force]    # Overwrite files that already exist'
  puts '  -s, [--skip]     # Skip files that already exist'
  puts '  -q, [--quiet]    # Suppress status output'
  puts
  puts "The available features are listed below, run 'origen add <feature> -h' for more info."
  puts

  print_generators
  puts
end

.invoke(name, args = ARGV, config = {}) ⇒ Object

Receives a namespace, arguments and the behavior to invoke the generator. It's used as the default entry point for generate, destroy and update commands.



42
43
44
45
46
47
48
# File 'lib/origen/code_generators.rb', line 42

def self.invoke(name, args = ARGV, config = {})
  load_generators
  if klass = find_by_name(name)
    args << '--help' if args.empty? && klass.arguments.any?(&:required?)
    klass.start(args, config)
  end
end

.load_generatorsObject



29
30
31
32
33
34
35
36
37
# File 'lib/origen/code_generators.rb', line 29

def self.load_generators
  return if @generators_loaded
  # Load Origen's generators
  Dir.glob("#{Origen.top}/lib/origen/code_generators/**/*.rb").sort.each do |file|
    require file
  end
  # Load generators from plugins, TBD what the rules will be here
  @generators_loaded = true
end

.no_color!Object

Remove the color from output.



17
18
19
# File 'lib/origen/code_generators.rb', line 17

def self.no_color!
  Thor::Base.shell = Thor::Shell::Basic
end

.origen_generatorsObject



21
22
23
# File 'lib/origen/code_generators.rb', line 21

def self.origen_generators
  @origen_generators ||= {}
end

.plugin_generatorsObject



25
26
27
# File 'lib/origen/code_generators.rb', line 25

def self.plugin_generators
  @plugin_generators ||= {}
end


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/origen/code_generators.rb', line 98

def self.print_generators
  load_generators
  origen_generators.each do |name, _gen|
    puts name
  end
  plugin_generators.each do |namespace, generators|
    puts
    generators.each do |_name, gen|
      puts "#{namespace}:#{gen}"
    end
  end
end