Class: Retrospec::Cli

Inherits:
Object
  • Object
show all
Includes:
Plugins
Defined in:
lib/retrospec/cli.rb

Class Method Summary collapse

Methods included from Plugins

#available_plugins, #discover_plugin, #discover_plugin_by_name, #excluded_classes, #gem_dir, #get_remote_data, #installed_plugins, #load_plugins, #plugin_classes, #plugin_map

Class Method Details

.list_available_pluginsObject



60
61
62
63
64
65
66
# File 'lib/retrospec/cli.rb', line 60

def self.list_available_plugins
    Retrospec::Cli.new.available_plugins.each do |name, plugin_data|
    puts "#{name}: #{plugin_data['project_url']}"
    puts "\tDescription: #{plugin_data['description']}"
    puts "\tInstallation: gem install #{plugin_data['gem']} --no-rdoc --no-ri"
  end
end

.list_installed_pluginsObject



68
69
70
71
72
# File 'lib/retrospec/cli.rb', line 68

def self.list_installed_plugins
  Retrospec::Cli.new.installed_plugins do |spec|
    puts "#{spec.name}"
  end
end

.runObject



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
# File 'lib/retrospec/cli.rb', line 10

def self.run
  cli = Retrospec::Cli.new
  # get the list of plugins and provide the plugin name as sub commands
  sub_commands = cli.plugin_map.keys
  cmd_help = sub_commands.join("\n")

  global_opts = Optimist::options do
    version "#{Retrospec::VERSION} (c) Corey Osman"
    banner <<-EOS
A framework to automate your development workflow by generating common files and test patterns.

Usage: retrospec [global options] plugin [plugin options]
Available subcommands:
#{cmd_help}

    EOS
    opt :enable_overwrite, "Enable overwriting of files, will prompt for each file",
        :type => :boolean, :default => false
    opt :enable_overwrite_all, "Always overwrites files without prompting",
        :type => :boolean, :default => false
    opt :module_path, "The path (relative or absolute) to the module directory" ,
        :type => :string, :required => false, :default => File.expand_path('.')
    opt :config_map, "The global retrospec config file", :type => :string, :required => false, :default => File.expand_path(File.join(ENV['HOME'], '.retrospec', 'config.yaml' ))
    opt :available_plugins, "Show an online list of available plugins", :type => :boolean, :require => false, :short => '-a'
    stop_on sub_commands
  end
  cmd = ARGV.shift # get the subcommand
  # these variables are used in the module helpers to determine if we should overwrite files
  ENV['RETROSPEC_OVERWRITE_ALL'] = global_opts[:enable_overwrite_all].to_s if global_opts[:enable_overwrite_all]
  ENV['RETROSPEC_OVERWRITE_ENABLE'] = global_opts[:enable_overwrite].to_s if global_opts[:enable_overwrite]

  if plugin_class = cli.plugin_map[cmd]
    # this is what generates the cli options for the plugin
    # this is also the main entry point that runs the plugin's cli
    global_config = Retrospec::Config.config_data(global_opts[:config_map])
    plugin_name   = plugin_class.send(:plugin_name)
    plugin_config = Retrospec::Config.plugin_context(global_config, plugin_name)
    plugin_class.send(:run_cli, global_opts, global_config, plugin_config)
  else
    if global_opts[:available_plugins]
      Retrospec::Cli.list_available_plugins
    else
      # this is the default action when no command is entered
      # at a later time we will try and use some magic to guess
      # what the user wants
      Optimist.educate
    end
  end
end