Sha256: 96dac4b22c5a40695edc23bc507fa23f81c4b2ea20d8800f8b8c53bd13ff9d5b

Contents?: true

Size: 1.61 KB

Versions: 28

Compression:

Stored size: 1.61 KB

Contents

require_relative '../../common/options/parser'
require_relative '../../common/version'

module Bake
  class BakeRtextServiceOptions < Parser
    attr_reader :loglevel # String
    attr_reader :patterns
    attr_reader :timeout # Number

    def initialize(argv)
      super(argv)

      @loglevel = 'info'
      @patterns = []
      @timeout = 3600

      add_option([""                 ], lambda { |x| @patterns.push(x)                                    })
      add_option(["-l", "--loglevel" ], lambda { |x| set_loglevel(x)                                      })
      add_option(["-t", "--timeout"  ], lambda { |x| @timeout = x.to_i                                    })
      add_option(["-h", "--help"     ], lambda { usage; ExitHelper.exit(0)                                })
      add_option(["--version"        ], lambda { Bake::Version.printBakeFormatVersion; ExitHelper.exit(0) })
    end

    def usage
      puts [
        "Usage: #{__FILE__} [options] <dir patterns>",
        "  -l, --loglevel [string], log level is one of [debug, info, warn, error, fatal].",
        "  -t, --timeout [number], idle timeout in seconds after which the service will shutdown. Default is 3600.",
        "  dir patterns, glob patterns."
      ].join("\n")
    end

    def parse_options()
      parse_internal(true)
      @patterns = ['./**'] unless @patterns.any?
    end
  end
end

def set_loglevel(level)
  unless level.match(/^debug|info|warn|error|fatal$/)
    Bake.formatter.printError("Error: \"#{level}\" is wrong log level type")
    Bake::ExitHelper.exit(1)
  end

  @loglevel = level
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bake-toolkit-2.72.0 lib/rtext-service/options/options.rb
bake-toolkit-2.71.0 lib/rtext-service/options/options.rb
bake-toolkit-2.70.1 lib/rtext-service/options/options.rb
bake-toolkit-2.70.0 lib/rtext-service/options/options.rb
bake-toolkit-2.69.0 lib/rtext-service/options/options.rb
bake-toolkit-2.68.1 lib/rtext-service/options/options.rb
bake-toolkit-2.68.0 lib/rtext-service/options/options.rb
bake-toolkit-2.67.0 lib/rtext-service/options/options.rb
bake-toolkit-2.66.0 lib/rtext-service/options/options.rb
bake-toolkit-2.65.2 lib/rtext-service/options/options.rb
bake-toolkit-2.65.1 lib/rtext-service/options/options.rb
bake-toolkit-2.65.0 lib/rtext-service/options/options.rb
bake-toolkit-2.64.4 lib/rtext-service/options/options.rb
bake-toolkit-2.64.3 lib/rtext-service/options/options.rb
bake-toolkit-2.64.2 lib/rtext-service/options/options.rb
bake-toolkit-2.64.1 lib/rtext-service/options/options.rb
bake-toolkit-2.64.0 lib/rtext-service/options/options.rb
bake-toolkit-2.63.2 lib/rtext-service/options/options.rb
bake-toolkit-2.63.1 lib/rtext-service/options/options.rb
bake-toolkit-2.63.0 lib/rtext-service/options/options.rb