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.



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

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

Class Method Details

.configurationObject



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

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



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

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



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

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



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

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



214
215
216
# File 'lib/gemsmith/cli.rb', line 214

def help task = nil
  say and super
end

#open(name) ⇒ Object



177
178
179
# File 'lib/gemsmith/cli.rb', line 177

def open name
  process_gem name, "edit"
end

#read(name) ⇒ Object



183
184
185
# File 'lib/gemsmith/cli.rb', line 183

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

#versionObject



208
209
210
# File 'lib/gemsmith/cli.rb', line 208

def version
  say Identity.version_label
end