Sha256: dbf06038cddda68d1e6beae8666fc6991cb86a2c0837dc7fe152aea5e8c2a1be

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

module Alf
  module Shell
    class Show < Shell::Command()
    
      options do |opt|
        @renderer_class = nil
        Renderer.each_renderer do |name,descr,clazz|
          opt.on("--#{name}", "Render output #{descr}"){ 
            @renderer_class = clazz
          }
        end
        
        @pretty = nil
        opt.on("--[no-]pretty", 
               "Enable/disable pretty print best effort") do |val|
          @pretty = val
        end

        @ff = nil
        opt.on("--ff=FORMAT", 
               "Specify the floating point format") do |val|
          @ff = val
        end
      end
        
      def run(argv, requester)
        # set requester and parse options
        @requester = requester
        argv = parse_options(argv, :split)

        # Set options on the requester
        requester.pretty = @pretty unless @pretty.nil?
        requester.rendering_options[:float_format] = @ff unless @ff.nil?
        requester.renderer_class = (@renderer_class || 
                                    requester.renderer_class || 
                                    Text::Renderer)

        # normalize args
        args = argv.first
        args = [ stdin_reader ] if args.empty?
        chain = Iterator.coerce(args.first, requester && requester.environment)

        # put a sorter
        if argv[1]
          chain = Alf::Operator::NonRelational::Sort.new([chain], argv[1])
        end

        chain
      end
    
      private 

      def stdin_reader
        if requester && requester.respond_to?(:stdin_reader)
          requester.stdin_reader
        else 
          Reader.coerce($stdin)
        end
      end

    end # class Show
  end # module Shell
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf-shell/alf/shell/command/show.rb
alf-0.12.1 lib/alf-shell/alf/shell/command/show.rb
alf-0.12.0 lib/alf-shell/alf/shell/command/show.rb
alf-0.11.1 lib/alf-shell/alf/shell/command/show.rb
alf-0.11.0 lib/alf-shell/alf/shell/command/show.rb