Sha256: 40fd85e2048ad095b9aa9774cdcd8ba64284c59c5d8e127d24bd4ba4278dfb1c

Contents?: true

Size: 962 Bytes

Versions: 2

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

require 'eac_cli/runner'
require 'eac_ruby_utils/core_ext'

module EacCli
  module RunnerWith
    module Help
      require_sub __FILE__, require_dependency: true
      common_concern do
        include ::EacCli::Runner

        runner_definition.alt do
          bool_opt '-h', '--help', 'Show help.', usage: true, required: true
          pos_arg :any_arg_with_help, repeat: true, optional: true, visible: false
        end

        set_callback :run, :before do
          help_run
        end
      end

      def help_run
        return unless show_help?

        puts help_text
        raise ::EacCli::Runner::Exit
      end

      def help_text
        r = ::EacCli::RunnerWith::Help::Builder.new(self.class.runner_definition).to_s
        r += help_extra_text if respond_to?(:help_extra_text)
        r
      end

      def show_help?
        parsed.help? && !if_respond(:run_subcommand?, false)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
eac_cli-0.27.4 lib/eac_cli/runner_with/help.rb
avm-tools-0.117.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb