Sha256: 5921e239660c1797afbcdf6a82133e5d4ff8f8468457816d6c6f5ed498fd1bd0

Contents?: true

Size: 1.74 KB

Versions: 18

Compression:

Stored size: 1.74 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 AwsEc2
  class Command < Thor
    class << self
      def dispatch(m, args, options, config)
        # Allow calling for help via:
        #   aws-ec2 command help
        #   aws-ec2 command -h
        #   aws-ec2 command --help
        #   aws-ec2 command -D
        #
        # as well thor's normal way:
        #
        #   aws-ec2 help command
        help_flags = Thor::HELP_MAPPINGS + ["help"]
        if args.length > 1 && !(args & help_flags).empty?
          args -= help_flags
          args.insert(-2, "help")
        end

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

        super
      end

      # Override command_help to include the description at the top of the
      # long_description.
      def command_help(shell, command_name)
        meth = normalize_command_name(command_name)
        command = all_commands[meth]
        alter_command_description(command)
        super
      end

      def alter_command_description(command)
        return unless command
        long_desc = if command.long_description
            "#{command.description}\n\n#{command.long_description}"
          else
            command.description
          end
        command.long_description = long_desc
      end
      private :alter_command_description
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/command.rb
aws-ec2-1.4.8 lib/aws_ec2/command.rb
aws-ec2-1.4.7 lib/aws_ec2/command.rb
aws-ec2-1.4.6 lib/aws_ec2/command.rb
aws-ec2-1.4.5 lib/aws_ec2/command.rb
aws-ec2-1.4.4 lib/aws_ec2/command.rb
aws-ec2-1.4.3 lib/aws_ec2/command.rb
aws-ec2-1.4.2 lib/aws_ec2/command.rb
aws-ec2-1.4.1 lib/aws_ec2/command.rb
aws-ec2-1.4.0 lib/aws_ec2/command.rb
aws-ec2-1.3.2 lib/aws_ec2/command.rb
aws-ec2-1.3.1 lib/aws_ec2/command.rb
aws-ec2-1.3.0 lib/aws_ec2/command.rb
aws-ec2-1.2.2 lib/aws_ec2/command.rb
aws-ec2-1.2.1 lib/aws_ec2/command.rb
aws-ec2-1.2.0 lib/aws_ec2/command.rb
aws-ec2-1.1.0 lib/aws_ec2/command.rb
aws-ec2-1.0.0 lib/aws_ec2/command.rb