Class: Gemsmith::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers::CLI, Helpers::Template, Thor::Actions
Defined in:
lib/gemsmith/cli.rb

Overview

The Command Line Interface (CLI) for the gem. rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Template

#gem_class, #gem_name, #gem_path, #rails_version, #render_namespace

Methods included from Helpers::CLI

inspect_gem, pick_gem, print_gems, process_gem

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Initialize.



103
104
105
106
107
108
# File 'lib/gemsmith/cli.rb', line 103

def initialize args = [], options = {}, config = {}
  super args, options, config
  @configuration = self.class.configuration
rescue Runcom::Errors::Base => error
  abort error.message
end

Class Method Details

.configurationObject

rubocop:disable Metrics/MethodLength



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gemsmith/cli.rb', line 30

def self.configuration
  Runcom::Configuration.new project_name: Identity.name, defaults: {
    year: Time.now.year,
    github_user: Git.github_user,
    gem: {
      label: "Undefined",
      name: "undefined",
      path: "undefined",
      class: "Undefined",
      platform: "Gem::Platform::RUBY",
      url: Git.github_url("undefined"),
      license: "MIT"
    },
    author: {
      name: Git.config_value("user.name"),
      email: Git.config_value("user.email"),
      url: ""
    },
    organization: {
      name: "",
      url: ""
    },
    versions: {
      ruby: RUBY_VERSION,
      rails: "5.1"
    },
    generate: {
      cli: false,
      rails: false,
      security: true,
      pry: true,
      guard: true,
      git_cop: true,
      rspec: true,
      reek: true,
      rubocop: true,
      scss_lint: false,
      git_hub: false,
      code_climate: false,
      gemnasium: false,
      circle_ci: false,
      patreon: false
    },
    publish: {
      sign: false
    }
  }
end

.generatorsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gemsmith/cli.rb', line 79

def self.generators
  [
    Generators::Gem,
    Generators::Documentation,
    Generators::Rake,
    Generators::CLI,
    Generators::Ruby,
    Generators::Rails,
    Generators::Rspec,
    Generators::GitCop,
    Generators::Reek,
    Generators::Rubocop,
    Generators::SCSSLint,
    Generators::CodeClimate,
    Generators::Guard,
    Generators::CircleCI,
    Generators::Bundler,
    Generators::GitHub,
    Generators::Pragma,
    Generators::Git
  ]
end

.source_rootObject

Overwrites Thor’s template source root.



25
26
27
# File 'lib/gemsmith/cli.rb', line 25

def self.source_root
  File.expand_path File.join(File.dirname(__FILE__), "templates")
end

Instance Method Details

#configObject



207
208
209
210
211
212
213
214
215
# File 'lib/gemsmith/cli.rb', line 207

def config
  path = configuration.path

  if options.edit? then `#{ENV["EDITOR"]} #{path}`
  elsif options.info?
    path ? say(path) : say("Configuration doesn't exist.")
  else help(:config)
  end
end

#generate(name) ⇒ Object

rubocop:disable Metrics/AbcSize :reek:TooManyStatements



174
175
176
177
178
179
180
181
182
183
# File 'lib/gemsmith/cli.rb', line 174

def generate name
  print_cli_and_rails_engine_option_error && return if options.cli? && options.rails?

  say_status :info, "Generating gem...", :green

  setup_configuration name: name, options: options.to_h
  self.class.generators.each { |generator| generator.run self, configuration: configuration }

  say_status :info, "Gem generation finished.", :green
end

#help(task = nil) ⇒ Object



225
226
227
# File 'lib/gemsmith/cli.rb', line 225

def help task = nil
  say and super
end

#open(name) ⇒ Object



187
188
189
# File 'lib/gemsmith/cli.rb', line 187

def open name
  process_gem name, "edit"
end

#read(name) ⇒ Object



193
194
195
# File 'lib/gemsmith/cli.rb', line 193

def read name
  say_status :error, "Gem home page is not defined.", :red unless process_gem(name, "visit")
end

#versionObject



219
220
221
# File 'lib/gemsmith/cli.rb', line 219

def version
  say Identity.version_label
end