Sha256: 7805c7fcd1910b2eef6592e66c2de53228e744cbbeb624181501caf891407392

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module Jets
  module Command
    class RunnerCommand < Base # :nodoc:
      include EnvironmentArgument

      self.environment_desc = "The environment for the runner to operate under (test/development/production)"

      no_commands do
        def help
          super
          say self.class.desc
        end
      end

      def self.banner(*)
        "#{super} [<'Some.ruby(code)'> | <filename.rb> | -]"
      end

      desc "runner", "Run Ruby code in the context of Jets app non-interactively"
      long_desc Help.text(:runner)
      def perform(code_or_file = nil, *command_argv)
        extract_environment_option_from_argument

        unless code_or_file
          help
          exit 1
        end

        require_application_and_environment!
        Jets.application.load_runner

        args = command_argv

        ARGV.replace(command_argv)

        if code_or_file == "-"
          eval($stdin.read, TOPLEVEL_BINDING, "stdin")
        elsif File.exist?(code_or_file)
          expanded_file_path = File.expand_path code_or_file
          $0 = expanded_file_path
          Kernel.load expanded_file_path
        else
          begin
            # Jets changed TOPLEVEL_BINDING to binding to have access to args
            # To keep args working https://github.com/boltops-tools/jets/pull/669
            eval(code_or_file, binding, __FILE__, __LINE__)
          rescue SyntaxError, NameError => e
            error "Please specify a valid ruby command or the path of a script to run."
            error "Run '#{self.class.executable} -h' for help."
            error ""
            error e
            exit 1
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/commands/runner/runner_command.rb
jets-5.0.12 lib/jets/commands/runner/runner_command.rb
jets-5.0.11 lib/jets/commands/runner/runner_command.rb
jets-5.0.10 lib/jets/commands/runner/runner_command.rb
jets-5.0.9 lib/jets/commands/runner/runner_command.rb
jets-5.0.8 lib/jets/commands/runner/runner_command.rb
jets-5.0.7 lib/jets/commands/runner/runner_command.rb
jets-5.0.6 lib/jets/commands/runner/runner_command.rb
jets-5.0.5 lib/jets/commands/runner/runner_command.rb
jets-5.0.4 lib/jets/commands/runner/runner_command.rb
jets-5.0.3 lib/jets/commands/runner/runner_command.rb
jets-5.0.2 lib/jets/commands/runner/runner_command.rb
jets-5.0.1 lib/jets/commands/runner/runner_command.rb
jets-5.0.0 lib/jets/commands/runner/runner_command.rb
jets-5.0.0.beta1 lib/jets/commands/runner/runner_command.rb