Sha256: 3a55a0217e391c0d10967d66b74c1902158161b0308500381b4dbd96abc06cff

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

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_mode: :kernel
      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

      # @param items [Enumerable<String>]
      # @return [String]
      def help_list_section(title, items)
        ::EacCli::RunnerWith::Help::Layout.list_section(title, items)
      end

      # @param items [Enumerable<String>]
      # @return [String]
      def help_join_sections(*sections)
        ::EacCli::RunnerWith::Help::Layout.join_sections(*sections)
      end

      def help_run
        return unless show_help?

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

      # @return [String]
      def help_text
        ::EacCli::RunnerWith::Help::Builder.new(self).to_s
      end

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

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_cli-0.37.0 lib/eac_cli/runner_with/help.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.74.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_cli-0.36.0 lib/eac_cli/runner_with/help.rb
eac_tools-0.73.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.72.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.70.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.70.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.69.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.69.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_cli-0.35.1 lib/eac_cli/runner_with/help.rb
eac_cli-0.34.1 lib/eac_cli/runner_with/help.rb
eac_tools-0.68.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_tools-0.67.1 sub/eac_cli/lib/eac_cli/runner_with/help.rb
eac_cli-0.35.0 lib/eac_cli/runner_with/help.rb
eac_tools-0.67.0 sub/eac_cli/lib/eac_cli/runner_with/help.rb