module Origen::CodeGenerators
Public Class Methods
Source
# File lib/origen/code_generators.rb, line 71 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 code generator named: #{name}" puts puts 'This is the list of available generators:' puts print_generators puts end
Source
# File lib/origen/code_generators.rb, line 94 def self.help(command = 'new') puts <<-END Add pre-built features and code snippets to your application. This command will generate code for 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 new <feature> -h' for more info." puts print_generators puts end
Show help message with available generators.
Source
# File lib/origen/code_generators.rb, line 56 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
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.
Source
# File lib/origen/code_generators.rb, line 66 def self.invoke_internal(name, args = ARGV, config = {}) load_internal_generators invoke(name, args, config) end
Like invoke, but will also make internal-use only generators available commands.
Source
# File lib/origen/code_generators.rb, line 29 def self.load_generators return if @generators_loaded # Load Origen's generators require_relative 'code_generators/block_common' require_relative 'code_generators/dut' require_relative 'code_generators/block' require_relative 'code_generators/feature' require_relative 'code_generators/model' require_relative 'code_generators/klass' require_relative 'code_generators/module' # Load generators from plugins, TBD what the API will be here @generators_loaded = true end
Source
# File lib/origen/code_generators.rb, line 45 def self.load_internal_generators return if @internal_generators_loaded require_relative 'code_generators/semver' require_relative 'code_generators/timever' @internal_generators_loaded = true end
Loaded separately so as not to pollute the generated list of generators available to users
Source
# File lib/origen/code_generators.rb, line 17 def self.no_color! Thor::Base.shell = Thor::Shell::Basic end
Remove the color from output.
Source
# File lib/origen/code_generators.rb, line 21 def self.origen_generators @origen_generators ||= {} end
Source
# File lib/origen/code_generators.rb, line 25 def self.plugin_generators @plugin_generators ||= {} end
Source
# File lib/origen/code_generators.rb, line 119 def self.print_generators load_generators origen_generators.each do |name, _gen| puts name end plugin_generators.each do |namespace, generators| next if namespace.to_s == 'origen_app_generators' puts generators.each do |_name, gen| puts "#{namespace}:#{gen}" end end end