Sha256: 1cf99b2a0a57f7d6b0bb8b7b32d47a0a7cbf4a79973a929849eb21879250d205

Contents?: true

Size: 667 Bytes

Versions: 2

Compression:

Stored size: 667 Bytes

Contents

require 'cl/format/table'
require 'cl/format/usage'

module Cl
  class Format
    class Cmd < Struct.new(:cmd)
      def format
        [banner, Table.new(opts).format].join("\n")
      end

      def banner
        banner = []
        banner << "#{cmd.purpose}\n" if cmd.purpose
        banner << "Usage: #{Usage.new(cmd).format}\n"
        banner
      end

      def opts
        cmd.opts.map do |opts, block|
          comment = opts.detect { |opt| !opt?(opt) }
          opts = opts.select { |opt| opt?(opt) }
          [opts.sort_by(&:size).join(' '), comment]
        end
      end

      def opt?(str)
        str.start_with?('-')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cl-0.0.4 lib/cl/format/cmd.rb
cl-0.0.2 lib/cl/format/cmd.rb