Sha256: faeb1e5c5fcebe40cfb0c3f32a7421447049c696408e6b04207b521a406d6459

Contents?: true

Size: 1.17 KB

Versions: 20

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require "cli/base"

module Icarus
  module Mod
    module CLI
      # Base class for all subcommands
      class SubcommandBase < Base
        class_option :verbose,
                     aliases: "-v", type: :boolean, repeatable: true, default: [true],
                     desc: "Increase verbosity. May be repeated for even more verbosity."

        no_commands do
          def check_false
            options[:verbose] = [] if options[:verbose].include?(false)
          end

          def verbose
            check_false
            options[:verbose]&.count || 0
          end

          def verbose?
            check_false
            options[:verbose]&.count&.positive?
          end
        end

        # rubocop:disable Style/OptionalBooleanParameter
        def self.banner(command, _namespace = nil, _subcommand = false)
          "#{basename} #{subcommand_prefix} #{command.usage}"
        end
        # rubocop:enable Style/OptionalBooleanParameter

        def self.subcommand_prefix
          name.gsub(/.*::/, "").gsub(/^[A-Z]/) { |match| match[0].downcase }.gsub(/[A-Z]/) { |match| "-#{match[0].downcase}" }
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
Icarus-Mod-Tools-2.1.3 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.1.2 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.1.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.1.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.0.4 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.0.3 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.0.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-2.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.9.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.8.2.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.8.2 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.8.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.8.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.7.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.7.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.6.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.5.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.5.0 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.4.1 lib/icarus/mod/cli/subcommand_base.rb
Icarus-Mod-Tools-1.4.0 lib/icarus/mod/cli/subcommand_base.rb