class Lita::CLI
The command line interface for Lita.
Public Class Methods
Returns the full destination file path for the given file, using the
supplied default_path
as the base if run as root, otherwise
falling back to the user's home directory. @param file_name [String]
The name of the file. @param default_path [String] The base of the file
path to use when run as root. @return [String] The full file path.
# File lib/lita/cli.rb, line 24 def self.file_path_for(file_name, default_path) base_path = Process.euid == 0 ? default_path : ENV["HOME"] File.join(base_path, file_name) end
The root file path for the templates directory. @note This is a magic method required by Thor for file operations. @return [String] The path.
# File lib/lita/cli.rb, line 15 def self.source_root Lita.template_root end
Public Instance Methods
Generates a new Lita adapter. @param name [String] The name for the new adapter. @return [void]
# File lib/lita/cli.rb, line 92 def adapter(name) config = generate_config(name, "adapter") generate_templates(config) post_messages(config) end
Generates a new Lita extension. @param name [String] The name for the new extension. @return [void]
# File lib/lita/cli.rb, line 112 def extension(name) config = generate_config(name, "extension") generate_templates(config) post_messages(config) end
Generates a new Lita handler. @param name [String] The name for the new handler. @return [void]
# File lib/lita/cli.rb, line 102 def handler(name) config = generate_config(name, "handler") generate_templates(config) post_messages(config) end
Generates a new Lita project. @param name [String] The directory name for the new project. @return [void]
# File lib/lita/cli.rb, line 84 def new(name = "lita") directory "robot", name end
Starts Lita. @return [void]
# File lib/lita/cli.rb, line 59 def start begin Bundler.require rescue Bundler::GemfileNotFound say I18n.t("lita.cli.no_gemfile_warning"), :red abort end if options[:daemonize] say I18n.t("lita.cli.daemon_deprecated"), :red Daemon.new( options[:pid_file], options[:log_file], options[:kill] ).daemonize end Lita.run(options[:config]) end
Outputs the current version of Lita. @return [void]
# File lib/lita/cli.rb, line 121 def version puts VERSION end
Private Instance Methods
# File lib/lita/cli.rb, line 128 def badges_message say I18n.t("lita.cli.badges_reminder"), :yellow end
# File lib/lita/cli.rb, line 132 def generate_config(name, plugin_type) name, gem_name = normalize_names(name) constant_name = name.split(/_/).map(&:capitalize).join namespace = "#{plugin_type}s" constant_namespace = namespace.capitalize spec_type = plugin_type == "handler" ? "lita_handler" : "lita" required_lita_version = Lita::VERSION.split(/\./)[0...-1].join(".") { name: name, gem_name: gem_name, constant_name: constant_name, plugin_type: plugin_type, namespace: namespace, constant_namespace: constant_namespace, spec_type: spec_type, required_lita_version: required_lita_version }.merge(generate_user_config).merge(optional_content) end
# File lib/lita/cli.rb, line 164 def generate_templates(config) name = config[:name] gem_name = config[:gem_name] namespace = config[:namespace] travis = config[:travis] target = File.join(Dir.pwd, gem_name) template( "plugin/lib/lita/plugin_type/plugin.tt", "#{target}/lib/lita/#{namespace}/#{name}.rb", config ) template("plugin/lib/plugin.tt", "#{target}/lib/#{gem_name}.rb", config) template( "plugin/spec/lita/plugin_type/plugin_spec.tt", "#{target}/spec/lita/#{namespace}/#{name}_spec.rb", config ) template("plugin/spec/spec_helper.tt", "#{target}/spec/spec_helper.rb", config) template("plugin/locales/en.yml.tt", "#{target}/locales/en.yml", config) if config[:plugin_type] == "handler" copy_file("plugin/templates/gitkeep", "#{target}/templates/.gitkeep") end copy_file("plugin/Gemfile", "#{target}/Gemfile") template("plugin/gemspec.tt", "#{target}/#{gem_name}.gemspec", config) copy_file("plugin/gitignore", "#{target}/.gitignore") copy_file("plugin/travis.yml", "#{target}/.travis.yml") if travis copy_file("plugin/Rakefile", "#{target}/Rakefile") template("plugin/README.tt", "#{target}/README.md", config) end
# File lib/lita/cli.rb, line 152 def generate_user_config git_user = %x`git config user.name`.chomp git_user = "TODO: Write your name" if git_user.empty? git_email = %x`git config user.email`.chomp git_email = "TODO: Write your email address" if git_email.empty? { author: git_user, email: git_email } end
# File lib/lita/cli.rb, line 196 def license_message say I18n.t("lita.cli.license_notice"), :yellow end
# File lib/lita/cli.rb, line 200 def normalize_names(name) name = name.downcase.sub(/^lita[_-]/, "") gem_name = "lita-#{name}" name = name.tr("-", "_") [name, gem_name] end
# File lib/lita/cli.rb, line 207 def optional_content travis = yes?(I18n.t("lita.cli.travis_question")) coveralls = yes?(I18n.t("lita.cli.coveralls_question")) if travis || coveralls say I18n.t("lita.cli.badges_message") badges = yes?(I18n.t("lita.cli.badges_question")) github_user = ask(I18n.t("lita.cli.github_user_question")) if badges end { travis: travis, coveralls: coveralls, badges: badges, github_user: github_user } end
# File lib/lita/cli.rb, line 223 def post_messages(config) license_message badges_message if config[:badges] end