Sha256: 238b622a8d8fb1bf77bab615c00ee91818b6136b9ff1740ea0e99412c6959a80

Contents?: true

Size: 1.41 KB

Versions: 40

Compression:

Stored size: 1.41 KB

Contents

require "cmdparse"

# Command line interpreter for Juicer
#
module Juicer
  class Cli

    def initialize
      @log = Juicer::LOGGER
      @log.level = Logger::INFO
    end

    # Set up command parser and parse arguments
    #
    def parse(arguments = ARGV)
      @cmd = CmdParse::CommandParser.new(true, true)
      @cmd.program_name = "juicer"
      @cmd.program_version = Juicer.version.split(".")

      @cmd.options = CmdParse::OptionParserWrapper.new do |opt|
        opt.separator "Global options:"
        opt.on("-v", "--verbose", "Be verbose when outputting info") { |t| @log.level = Logger::DEBUG }
        opt.on("-q", "--quiet", "Only log warnings and errors") { |t| @log.level = Logger::WARN }
      end

      add_commands
      @cmd.parse(arguments)
      @log.close
    rescue SystemExit
      exit
    end

    # Run CLI
    #
    def self.run(arguments = ARGV)
      juicer = self.new
      juicer.parse(arguments)
    end

   private
    # Adds commands supported by juicer. Instantiates all classes in the
    # Juicer::Command namespace.
    #
    def add_commands
      @cmd.add_command(CmdParse::HelpCommand.new)
      @cmd.add_command(CmdParse::VersionCommand.new)

      if Juicer.const_defined?("Command")
        Juicer::Command.constants.each do |const|
          const = Juicer::Command.const_get(const)
          @cmd.add_command(const.new(@log)) if const.kind_of?(Class)
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 4 rubygems

Version Path
juicer-1.2.0 lib/juicer/cli.rb
cjohansen-juicer-0.2.4 lib/juicer/cli.rb
cjohansen-juicer-0.2.5 lib/juicer/cli.rb
juicer-1.1.2 lib/juicer/cli.rb
juicer-1.1.1 lib/juicer/cli.rb
juicer-1.1.0 lib/juicer/cli.rb
juicer-1.0.22 lib/juicer/cli.rb
juicer-1.0.21 lib/juicer/cli.rb
juicer-1.0.20 lib/juicer/cli.rb
juicer-1.0.19 lib/juicer/cli.rb
juicer-1.0.18 lib/juicer/cli.rb
juicer-1.0.17 lib/juicer/cli.rb
juicer-1.0.16 lib/juicer/cli.rb
juicer-1.0.15 lib/juicer/cli.rb
juicer-1.0.14 lib/juicer/cli.rb
juicer-1.0.13 lib/juicer/cli.rb
psyho_juicer-1.0.11 lib/juicer/cli.rb
juicer-1.0.12 lib/juicer/cli.rb
juicer-1.0.11 lib/juicer/cli.rb
juicer-1.0.10 lib/juicer/cli.rb