Class: Brut::CLI::Apps::New::App::Segment

Inherits:
Commands::BaseCommand show all
Defined in:
lib/brut/cli/apps/new/app.rb

Instance Attribute Summary

Attributes inherited from Commands::BaseCommand

#parent_command

Instance Method Summary collapse

Methods inherited from Commands::BaseCommand

#argv, #bootstrap?, #commands, #default_rack_env, #delegate_to_command, #detailed_description, #env, #env_vars, #execute, #name, #options, #puts, #stdin, #system!, #theme

Instance Method Details

#acceptsObject



263
264
265
# File 'lib/brut/cli/apps/new/app.rb', line 263

def accepts = [
  [ Pathname, ->(value) { Pathname(value) } ],
]

#args_descriptionObject



261
# File 'lib/brut/cli/apps/new/app.rb', line 261

def args_description = "segment_name"

#descriptionObject



259
# File 'lib/brut/cli/apps/new/app.rb', line 259

def description = "Add a segement to your app to provide additional pre-configured functionality"

#optsObject



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/brut/cli/apps/new/app.rb', line 267

def opts = [
  [
    "--dir=DIR",
    Pathname,
    "Path to your app. Default is the current directory",
  ],
  [ 
    "--dry-run",
    "Only show what would happen, don't actually do anything",
  ],
]

#runObject



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/brut/cli/apps/new/app.rb', line 279

def run
  options.set_default(:dir,Pathname.pwd)

  segment_name = argv[0]
  if !segment_name
    error "segment_name is required"
    return 1
  end
  if options.demo?
    segment_names << "demo"
  end

  project_root = options.dir.expand_path
  versions = Brut::CLI::Apps::New::Versions.new


  if options.dry_run?
    puts "Dry Run"
    Brut::CLI::Apps::New::Ops::BaseOp.dry_run = true
  end

  templates_dir = Pathname(
    Gem::Specification.find_by_name("brut").gem_dir
  ) / "templates"

  segment = if segment_name == "sidekiq"
               Brut::CLI::Apps::New::Segments::Sidekiq.new(
                 project_root:,
                 templates_dir:
               )
             elsif segment_name == "heroku"
               Brut::CLI::Apps::New::Segments::Heroku.new(
                 project_root:,
                 templates_dir:
               )
             end
  if !segment
    error "'#{segment_name}' is not a segment. Allowed values: sidekiq, heroku"
    return 1
  end

  puts "Adding #{segment_name} to this app"
  segment.add!
  segment.output_post_add_messaging(stdout: execution_context.stdout)
  0
end