Class: CreateRailsApp::CLI
- Inherits:
-
Object
- Object
- CreateRailsApp::CLI
- Defined in:
- lib/create_rails_app/cli.rb
Overview
Main entry point that orchestrates the entire create-rails-app flow.
Parses CLI flags, detects installed Rails versions, runs the interactive wizard (or loads a preset), builds the rails new command, and executes it. All collaborators are injected via constructor for testability.
Defined Under Namespace
Classes: VersionChoice
Class Method Summary collapse
-
.start(argv = ARGV, out: $stdout, err: $stderr, store: Config::Store.new, detector: Detection::Runtime.new, rails_detector: Detection::RailsVersions.new, runner: nil, prompter: nil, palette: nil) ⇒ Integer
Constructs and runs a CLI instance with the given arguments.
Instance Method Summary collapse
-
#initialize(argv:, out:, err:, store:, detector:, rails_detector:, runner:, prompter:, palette:) ⇒ CLI
constructor
A new instance of CLI.
-
#run ⇒ Integer
Runs the CLI: parses flags, dispatches to the appropriate action, and returns an exit code.
Constructor Details
#initialize(argv:, out:, err:, store:, detector:, rails_detector:, runner:, prompter:, palette:) ⇒ CLI
Returns a new instance of CLI.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/create_rails_app/cli.rb', line 64 def initialize(argv:, out:, err:, store:, detector:, rails_detector:, runner:, prompter:, palette:) @argv = argv.dup @out = out @err = err @store = store @detector = detector @rails_detector = rails_detector @runner = runner @prompter = prompter @palette = palette || UI::Palette.new = {} end |
Class Method Details
.start(argv = ARGV, out: $stdout, err: $stderr, store: Config::Store.new, detector: Detection::Runtime.new, rails_detector: Detection::RailsVersions.new, runner: nil, prompter: nil, palette: nil) ⇒ Integer
Constructs and runs a CLI instance with the given arguments.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/create_rails_app/cli.rb', line 30 def self.start( argv = ARGV, out: $stdout, err: $stderr, store: Config::Store.new, detector: Detection::Runtime.new, rails_detector: Detection::RailsVersions.new, runner: nil, prompter: nil, palette: nil ) instance = new( argv: argv, out: out, err: err, store: store, detector: detector, rails_detector: rails_detector, runner: runner || Runner.new(out: out), prompter: prompter, palette: palette ) instance.run end |
Instance Method Details
#run ⇒ Integer
Runs the CLI: parses flags, dispatches to the appropriate action, and returns an exit code.
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 |
# File 'lib/create_rails_app/cli.rb', line 81 def run validate_top_level_flags! return print_version if [:version] return print_help if [:help] return doctor if [:doctor] return list_presets if [:list_presets] return show_preset if [:show_preset] return delete_preset if [:delete_preset] validate_preset_name!([:save_preset]) if [:save_preset] runtime_versions = @detector.detect installed_rails = @rails_detector.detect version_choice = resolve_rails_version!(installed_rails) compatibility_entry = Compatibility::Matrix.for(version_choice.version || "#{version_choice.series}.0") builder = CommandBuilder.new app_name = resolve_app_name! if [:minimal] Options::Validator.new(compatibility_entry).validate!(app_name: app_name, options: {}) version_choice = install_and_update_version!(version_choice) if version_choice.needs_install command = builder.build(app_name: app_name, rails_version: version_choice.version, options: {}, minimal: true) @runner.run!(command, dry_run: [:dry_run]) return 0 end = if [:preset] else run_interactive_wizard!( app_name: app_name, builder: builder, compatibility_entry: compatibility_entry, last_used: @store.last_used, runtime_versions: runtime_versions, version_choice: version_choice ) end Options::Validator.new(compatibility_entry).validate!(app_name: app_name, options: ) version_choice = install_and_update_version!(version_choice) if version_choice.needs_install command = builder.build( app_name: app_name, rails_version: version_choice.version, options: , minimal: false ) @runner.run!(command, dry_run: [:dry_run]) unless [:dry_run] begin @store.save_last_used() save_preset_if_requested() rescue ValidationError, ConfigError => e @err.puts("Warning: #{e.message}") rescue Interrupt @err.puts('Skipped preset save.') end end 0 rescue OptionParser::ParseError, ArgumentError, Error => e @err.puts(e.) 1 rescue Interrupt @err.puts(palette.color(:exit_message, 'See ya!')) 130 end |