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, #print, #puts, #stdin, #system!, #theme

Instance Method Details

#acceptsObject



268
269
270
# File 'lib/brut/cli/apps/new/app.rb', line 268

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

#args_descriptionObject



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

def args_description = "segment_name"

#descriptionObject



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

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

#optsObject



272
273
274
275
276
277
278
279
280
281
282
# File 'lib/brut/cli/apps/new/app.rb', line 272

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



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
325
326
327
328
329
330
331
332
333
334
# File 'lib/brut/cli/apps/new/app.rb', line 284

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:
               )
             elsif segment_name == "docker-deploy"
               Brut::CLI::Apps::New::Segments::DockerDeploy.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