Class: Brut::CLI::Apps::New::App
- Inherits:
-
Commands::BaseCommand
- Object
- Commands::BaseCommand
- Brut::CLI::Apps::New::App
- Defined in:
- lib/brut/cli/apps/new/app.rb,
lib/brut/cli/apps/new/old_app.rb
Defined Under Namespace
Classes: Segment
Instance Attribute Summary
Attributes inherited from Commands::BaseCommand
Instance Method Summary collapse
-
#accepts ⇒ Object
-
#args_description ⇒ Object
-
#create! ⇒ Object
-
#description ⇒ Object
-
#initialize(current_dir:, app_options:, out:, err:) ⇒ App
constructor
A new instance of App.
-
#name ⇒ Object
-
#opts ⇒ Object
-
#run ⇒ Object
Methods inherited from Commands::BaseCommand
#argv, #bootstrap?, #commands, #default_command, #default_command_class, #default_rack_env, #env, #env_vars, #execute, #options, #puts, #stderr, #stdin, #stdout, #system!
Constructor Details
#initialize(current_dir:, app_options:, out:, err:) ⇒ App
Returns a new instance of App.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/brut/cli/apps/new/old_app.rb', line 4 def initialize(current_dir:, app_options:, out:, err:) @out = out @app_options = @out.puts "Creating app with these options:\n" @out.puts "App name: #{.app_name}" @out.puts "App ID: #{.app_id}" @out.puts "Prefix: #{.prefix}" @out.puts "Organization: #{.organization}" @out.puts "Include demo? #{.demo}\n" if .dry_run? @out.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" @base = Brut::CLI::Apps::New::Base.new( app_options:, current_dir:, templates_dir: ) @segments = [ Brut::CLI::Apps::New::Segments::BareBones.new( app_options:, current_dir:, templates_dir:, ), ] if .demo? @segments << Brut::CLI::Apps::New::Segments::Demo.new( app_options:, current_dir:, templates_dir: ) end .segments.each do |segment| case segment when "heroku" @segments << Brut::CLI::Apps::New::Segments::Heroku.new( project_root: @base.project_root, templates_dir: ) when "sidekiq" @segments << Brut::CLI::Apps::New::Segments::Sidekiq.new( project_root: @base.project_root, templates_dir: ) else raise "Segment #{segment} is not supported" end end @segments.sort! end |
Instance Method Details
#accepts ⇒ Object
10 11 12 13 14 15 |
# File 'lib/brut/cli/apps/new/app.rb', line 10 def accepts = [ Brut::CLI::Apps::New::Prefix, Brut::CLI::Apps::New::AppId, Brut::CLI::Apps::New::Organization, [ Pathname, ->(value) { Pathname(value) } ], ] |
#args_description ⇒ Object
8 |
# File 'lib/brut/cli/apps/new/app.rb', line 8 def args_description = "app_name" |
#create! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/brut/cli/apps/new/old_app.rb', line 62 def create! @out.puts "Creating Base app" @base.create! @segments.each do |segment| @out.puts "Creating segment: #{segment.class.friendly_name}" segment.add! end @out.puts "#{@app_options.app_name} was created\n\n" @out.puts "Time to get building:" @out.puts "1. cd #{@app_options.app_name}" @out.puts "2. dx/build" @out.puts "3. dx/start" @out.puts "4. [ in another terminal ] dx/exec bash" @out.puts "5. [ inside the Docker container ] bin/setup" @out.puts "6. [ inside the Docker container ] bin/dev" @out.puts "7. Visit http://localhost:6502 in your browser" @out.puts "8. [ inside the Docker container ] bin/setup help # to see more commands" end |
#description ⇒ Object
7 |
# File 'lib/brut/cli/apps/new/app.rb', line 7 def description = "Create a Brut App or modify an existing one with new segments" |
#name ⇒ Object
6 |
# File 'lib/brut/cli/apps/new/app.rb', line 6 def name = "new" |
#opts ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/brut/cli/apps/new/app.rb', line 17 def opts = [ [ "--dir=DIR", Pathname, "Path where you want your app created. Default is the current directory", ], [ "--app-id=ID", Brut::CLI::Apps::New::AppId, "App identifier, which must be able to be used as a hostname or other Internet identifier. Derived from your app name, if omitted" ], [ "--[no-]interactive", "Don't ask for user input, just assume default answers", ], [ "--organization=ORG", Brut::CLI::Apps::New::Organization, "Organization name, e.g. what you'd use for GitHub. Defaults to the app-id value" ], [ "--prefix=PREFIX", Brut::CLI::Apps::New::Prefix, "Two-character prefix for external IDs and autonomous custom elements. Derived from your app-id, if omitted." ], [ "--segments=SEGMENTS", Array, "Comma-delimited list of segment names to add additional behavior to your new app. Current values: heroku, sidekiq, demo", ], [ "--dry-run", "Only show what would happen, don't actually do anything" ], [ "--[no-]demo", "Include, or not, additional files that demonstrate Brut's features (default is true for now)" ], ] |
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/brut/cli/apps/new/app.rb', line 58 def run app_name = argv[0] if !app_name stderr.puts "app_name is required" return 1 end .set_default(:app_id, Brut::CLI::Apps::New::AppId.from_app_name(app_name)) .set_default(:prefix, Brut::CLI::Apps::New::Prefix.from_app_id(.app_id)) .set_default(:organization, Brut::CLI::Apps::New::Prefix.from_app_id(.app_id)) .set_default(:demo, true) .set_default(:interactive, true) .set_default(:dir,Pathname.pwd) segment_names = Set.new(.segments) if .demo? segment_names << "demo" end current_dir = .dir. versions = Brut::CLI::Apps::New::Versions.new templates_dir = Pathname( Gem::Specification.find_by_name("brut").gem_dir ) / "templates" base = Brut::CLI::Apps::New::Base.new( app_name:, options:, versions:, current_dir:, templates_dir: ) segments = [ Brut::CLI::Apps::New::Segments::BareBones.new( app_name:, options:, versions:, current_dir:, templates_dir:, ), ] if .demo? segments << Brut::CLI::Apps::New::Segments::Demo.new( app_name:, options:, versions:, current_dir:, templates_dir: ) end segment_names.each do |segment| case segment when "heroku" segments << Brut::CLI::Apps::New::Segments::Heroku.new( project_root: base.project_root, templates_dir: ) when "sidekiq" segments << Brut::CLI::Apps::New::Segments::Sidekiq.new( project_root: base.project_root, templates_dir: ) when "demo" # handled above else raise "Segment #{segment} is not supported" end end segments.sort! stdout.puts "Creating a new Brut app with these options:\n" stdout.puts "App Name : #{app_name}" stdout.puts "Path to New App : #{current_dir / app_name}" stdout.puts "App Id : #{.app_id}" stdout.puts "Prefix : #{.prefix}" stdout.puts "Organization : #{.organization}" stdout.puts "Segments : #{segments.map(&:class).map(&:segment_name).join(", ")}" stdout.puts if .dry_run? stdout.puts "Dry Run only" Brut::CLI::Apps::New::Ops::BaseOp.dry_run = true end if .interactive? stdout.puts "Proceed? (Y/N)" answer = stdin.gets if answer.downcase.strip.chomp != "y" stdout.puts "Aborting...." exit end end stdout.puts "Creating Base app" base.create! segments.each do |segment| stdout.puts "Creating segment: #{segment.class.friendly_name}" segment.add! end stdout.puts "#{.app_name} was created\n\n" stdout.puts "Time to get building:" stdout.puts "1. cd #{current_dir / app_name}" stdout.puts "2. dx/build" stdout.puts "3. dx/start" stdout.puts "4. [ in another terminal ] dx/exec bash" stdout.puts "5. [ inside the Docker container ] bin/setup" stdout.puts "6. [ inside the Docker container ] bin/dev" stdout.puts "7. Visit http://localhost:6502 in your browser" stdout.puts "8. [ inside the Docker container ] bin/setup help # to see more commands" end |