Class: Gemsmith::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers::CLI, Helpers::Template, Thor::Actions, ThorPlus::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.



102
103
104
105
# File 'lib/gemsmith/cli.rb', line 102

def initialize args = [], options = {}, config = {}
  super args, options, config
  @configuration = {}
end

Class Method Details

.configurationObject

rubocop:disable Metrics/MethodLength



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 32

def self.configuration
  Runcom::Configuration.new file_name: Identity.file_name, defaults: {
    year: Time.now.year,
    github_user: Git.github_user,
    gem: {
      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.0"
    },
    generate: {
      cli: false,
      rails: false,
      security: true,
      pry: true,
      guard: true,
      rspec: true,
      reek: true,
      rubocop: true,
      scss_lint: false,
      git_hub: false,
      code_climate: false,
      gemnasium: false,
      travis: 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
# 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::Reek,
    Generators::Rubocop,
    Generators::SCSSLint,
    Generators::CodeClimate,
    Generators::Guard,
    Generators::Travis,
    Generators::Bundler,
    Generators::GitHub,
    Generators::Pragma,
    Generators::Git
  ]
end

.source_rootObject

Overwrites Thor’s template source root.



27
28
29
# File 'lib/gemsmith/cli.rb', line 27

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

Instance Method Details

#configObject



199
200
201
202
203
204
205
206
# File 'lib/gemsmith/cli.rb', line 199

def config
  path = self.class.configuration.computed_path

  if options.edit? then `#{editor} #{path}`
  elsif options.info? then say(path)
  else help(:config)
  end
end

#generate(name) ⇒ Object

rubocop:disable Metrics/AbcSize



166
167
168
169
170
171
172
173
174
175
# File 'lib/gemsmith/cli.rb', line 166

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

  info "Generating gem..."

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

  info "Gem generation finished."
end

#help(task = nil) ⇒ Object



216
217
218
# File 'lib/gemsmith/cli.rb', line 216

def help task = nil
  say and super
end

#open(name) ⇒ Object



179
180
181
# File 'lib/gemsmith/cli.rb', line 179

def open name
  process_gem name, "edit"
end

#read(name) ⇒ Object



185
186
187
# File 'lib/gemsmith/cli.rb', line 185

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

#versionObject



210
211
212
# File 'lib/gemsmith/cli.rb', line 210

def version
  say Identity.version_label
end