Class: Bridgetown::Commands::Base
- Inherits:
-
Thor
- Object
- Thor
- Bridgetown::Commands::Base
- Defined in:
- bridgetown-core/lib/bridgetown-core/commands/base.rb
Class Method Summary collapse
-
.display_rake_tasks(rake) ⇒ Object
-
.exit_on_failure? ⇒ Boolean
-
.find_command_possibilities(subcommand) ⇒ Object
Override single character commands if necessary.
-
.handle_no_command_error(cmd, _has_namespace = $thor_runner) ⇒ Object
rubocop:disable Style/GlobalVars.
-
.load_rake_tasks(rake) ⇒ Object
Instance Method Summary collapse
-
#dream ⇒ Object
-
#help(subcommand = nil) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
.display_rake_tasks(rake) ⇒ Object
30 31 32 33 34 35 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 30 def display_rake_tasks(rake) rake..show_all_tasks = true rake..show_task_pattern = Regexp.new("") rake..show_tasks = :tasks rake.display_tasks_and_comments end |
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 9 def self.exit_on_failure? true end |
.find_command_possibilities(subcommand) ⇒ Object
Override single character commands if necessary
19 20 21 22 23 24 25 26 27 28 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 19 def find_command_possibilities(subcommand) case subcommand when "c" ["console"] when "s" ["start"] else super end end |
.handle_no_command_error(cmd, _has_namespace = $thor_runner) ⇒ Object
rubocop:disable Style/GlobalVars
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 77 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 47 def handle_no_command_error(cmd, _has_namespace = $thor_runner) require "rake" Rake::TaskManager. = true Rake.with_application do |rake| rake.standard_exception_handling do rakefile, _location = rake.find_rakefile_location unless rakefile puts "No Rakefile found (searching: #{rake.class::DEFAULT_RAKEFILES.join(", ")})\n\n" # rubocop:disable Layout/LineLength new.invoke("help") return # rubocop:disable Lint/NonLocalExitFromIterator end rake.init("bridgetown") load_rake_tasks(rake) end if Rake::Task.task_defined?(cmd.split("[")[0]) rake.top_level else puts "Unknown task: #{cmd.split("[")[0]}\n\nHere's a list of tasks you can run:" display_rake_tasks(rake) end rescue RuntimeError => e # re-raise error unless it's an error through Minitest raise e unless e..include?("ruby -Ilib:test") Bridgetown.logger.error "test aborted!" Bridgetown.logger.error e. exit(false) end end |
.load_rake_tasks(rake) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 37 def load_rake_tasks(rake) rake.load_rakefile tasks = rake.instance_variable_get(:@tasks) rake.instance_variable_set(:@tasks, tasks.reject do |_k, v| v.locations.first&.include?("/lib/rails/tasks/") || v.locations.first&.include?("/lib/rake/dsl_definition") end) end |
Instance Method Details
#dream ⇒ Object
82 83 84 85 86 87 88 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 82 def dream puts "" puts "🎶 The Dream of the 90s is Alive in Portland... ✨" puts " https://youtu.be/U4hShMEk1Ew" puts " https://youtu.be/0_HGqPGp9iY" puts "" end |
#help(subcommand = nil) ⇒ Object
rubocop:disable Metrics/MethodLength
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 |
# File 'bridgetown-core/lib/bridgetown-core/commands/base.rb', line 91 def help(subcommand = nil) # rubocop:disable Metrics/MethodLength if subcommand && respond_to?(subcommand) klass = Kernel.const_get("Bridgetown::Commands::#{subcommand.capitalize}") klass.start(["-h"]) else puts "Bridgetown v#{Bridgetown::VERSION.magenta} \"#{Bridgetown::CODE_NAME.yellow}\"" \ " is a next-generation, progressive site generator & fullstack framework, powered by Ruby" puts "" puts "Usage:" puts " bridgetown <command> [options]" puts "" super require "rake" Rake::TaskManager. = true Rake.with_application do |rake| rake.instance_variable_set(:@name, " bridgetown") rake.standard_exception_handling do rakefile, _location = rake.find_rakefile_location return unless rakefile # rubocop:disable Lint/NonLocalExitFromIterator self.class.load_rake_tasks(rake) puts "Available Rake Tasks:" self.class.display_rake_tasks(rake) end end end rescue LoadError nil end |