Sha256: 9f31b4ee1eaa3c6d8ddee2fcd0e354128c485c782f91632cafb1e976a119b6b9

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

require 'thor'

# Override thor's long_desc identation behavior
# https://github.com/erikhuda/thor/issues/398
class Thor
  module Shell
    class Basic
      def print_wrapped(message, options = {})
        message = "\n#{message}" unless message[0] == "\n"
        stdout.puts message
      end
    end
  end
end

module CliTemplate
  class Command < Thor
    class << self
      def dispatch(m, args, options, config)
        # Allow calling for help via:
        #   cli-template command help
        #   cli-template command -h
        #   cli-template command --help
        #   cli-template command -D
        #
        # as well thor's normal way:
        #
        #   cli-template help command
        help_flags = Thor::HELP_MAPPINGS + ["help"]
        if args.length > 1 && !(args & help_flags).empty?
          args -= help_flags
          args.insert(-2, "help")
        end

        #   cli-template version
        #   cli-template --version
        #   cli-template -v
        version_flags = ["--version", "-v"]
        if args.length == 1 && !(args & version_flags).empty?
          args = ["version"]
        end

        super
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cli-template-4.0.1 lib/cli_template/command.rb
cli-template-4.0.0 lib/cli_template/command.rb
cli-template-3.5.1 lib/cli-template/command.rb
cli-template-3.5.0 lib/cli-template/command.rb
cli-template-3.4.0 lib/cli-template/command.rb
cli-template-3.3.0 lib/cli-template/command.rb
cli-template-3.2.0 lib/cli-template/command.rb
cli-template-3.1.0 lib/cli-template/command.rb
cli-template-3.0.0 lib/cli-template/command.rb