lib/jets/cli/main.rb in jets-cli-0.1.0 vs lib/jets/cli/main.rb in jets-cli-0.1.1

- old
+ new

@@ -1,8 +1,9 @@ # frozen_string_literal: true require "thor" +require "bundler" module Jets module CLI class Main < Thor RESERVED_COMMANDS = %i[all generate gems engines].freeze @@ -26,15 +27,55 @@ define_method(command) do |*args| bundle(*(["exec", command] + args)) end end + desc "NAME console", "Run `rails console` for given engine" + long_desc <<-LONGDESC + `jets NAME console` will run Rails console for given engine. + LONGDESC + def console + exec_command("./bin/console") + end + desc "NAME rails [OPTIONS]", "Run `rails` command for given engine" + long_desc <<-LONGDESC + `jets NAME rails` will run Rails commands for given engine. + LONGDESC + def rails(*args) exec_command("./bin/rails", *args) end + desc "NAME yarn", "Run `yarn` for given engine" + long_desc <<-LONGDESC + `jets NAME yarn` will run yarn for given engine. + LONGDESC + def yarn(*args) + exec_command("yarn", *args) + end + + def method_missing(engine_or_gem, *args) + options = + case engine_or_gem.to_s + when "all" + { all: true } + when "all-gems" + { all_gems: true } + when "all-engines" + { all_engines: true } + when *engines + { engine: engine_or_gem.to_s } + when *gems + { engine: engine_or_gem.to_s, gem: true } + end + + return super if options.nil? + + self.class.start(args, class_options: options) + end + private def engine @engine ||= options[:engine] || ENV["ENGINE"] end @@ -50,11 +91,11 @@ def engine_root @engine_root ||= "#{options[:gem] ? "gems" : "engines"}/#{engine}" end def app_root - # @app_root ||= File.expand_path("..", __dir__) + # @app_root ||= File.expand_path("../../..", __dir__) @app_root ||= if defined?(Rails) Rails.root else Dir.pwd end @@ -87,10 +128,10 @@ end message = "Command `#{command}` (from #{dir}) returned non-zero exit code" $stdout.puts message - raise CommandFailedException, message unless options[:ignore_failures] + raise ::Jets::CLI::Exceptions::CommandFailed, message unless options[:ignore_failures] end end end end