Sha256: 8e29678d61f6e9ec45826dd11ec18972746eb21a225b4b6c67e2b572e2d6ad04

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'eac_cli/core_ext'
require 'eac_cli/speaker'
require 'eac_config/node'
require 'eac_fs/cache'
require 'eac_ruby_utils/speaker'

module EacRubyBase0
  module Runner
    require_sub __FILE__
    enable_speaker
    common_concern do
      include ::EacCli::RunnerWith::Help
      include ::EacCli::RunnerWith::Subcommands
      runner_definition do
        bool_opt '-q', '--quiet', 'Quiet mode.'
        bool_opt '-I', '--no-input', 'Fail if a input is requested.'
        subcommands
        alt do
          bool_opt '-V', '--version', 'Show version.', usage: true, required: true
        end
      end
    end

    def run
      on_context do
        if parsed.version?
          show_version
        else
          run_with_subcommand
        end
      end
    end

    def application_version
      runner_context.call(:application).version.to_s
    end

    def on_context
      ::EacRubyUtils::Speaker.context.on(build_speaker) do
        ::EacConfig::Node.context.on(runner_context.call(:application).build_config) do
          ::EacFs::Cache.context.on(application.fs_cache) do
            yield
          end
        end
      end
    end

    def show_version
      out("#{application_version}\n")
    end

    class FailIfRequestInput
      enable_speaker

      %w[gets noecho].each do |method|
        define_method(method) do
          raise "Input method requested (\"#{method}\") and option --no-input is set"
        end
      end
    end

    private

    def build_speaker
      options = {}
      options[:err_out] = ::StringIO.new if parsed.quiet?
      options[:in_in] = FailIfRequestInput.new if parsed.no_input?
      ::EacCli::Speaker.new(options)
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
ehbrs-tools-0.28.1 vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb
avm-tools-0.107.0 vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb
eac_ruby_base0-0.11.0 lib/eac_ruby_base0/runner.rb
ehbrs-tools-0.28.0 vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb