Sha256: 48b0ac1174a6cb7dc18513397083c33b87d7034edea5dd0ba52b1fc31af41eae

Contents?: true

Size: 1.26 KB

Versions: 34

Compression:

Stored size: 1.26 KB

Contents

require "optparse"
require "yaml"

require "timber/cli/api"
require "timber/cli/installers"
require "timber/cli/io"
require "timber/version"

module Timber
  # @private
  class CLI
    AVAILABLE_COMMANDS = %w(install).freeze

    class << self
      attr_accessor :options

      def run(argv = ARGV)
        global = global_option_parser
        global.order!(argv)
        command = argv.shift

        case command
        when nil
          # Print help
          puts global
          exit(0)

        when "install"
          api_key = argv.shift
          io = IO.new
          Installers.run(api_key, io)

        else
          puts "Command '#{command}' does not exist, run timber -h to "\
            "see the help"
          exit(1)
        end
      end

      def global_option_parser
        OptionParser.new do |o|
          o.banner = "Usage: timber <command> [options]"

          o.on "-v", "--version", "Print version and exit" do |_arg|
            puts "Timber #{Timber::VERSION}"
            exit(0)
          end

          o.on "-h", "--help", "Show help and exit" do
            puts o
            exit(0)
          end

          o.separator ""
          o.separator "Available commands: #{AVAILABLE_COMMANDS.join(", ")}"
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
timber-2.6.2 lib/timber/cli.rb
timber-2.6.1 lib/timber/cli.rb
timber-2.6.0 lib/timber/cli.rb
timber-2.6.0.pre.beta2 lib/timber/cli.rb
timber-2.6.0.pre.beta1 lib/timber/cli.rb
timber-2.5.1 lib/timber/cli.rb
timber-2.5.0 lib/timber/cli.rb
timber-2.4.0 lib/timber/cli.rb
timber-2.3.4 lib/timber/cli.rb
timber-2.3.3 lib/timber/cli.rb
timber-2.3.2 lib/timber/cli.rb
timber-2.3.1 lib/timber/cli.rb
timber-2.3.0 lib/timber/cli.rb
timber-2.2.3 lib/timber/cli.rb
timber-2.2.2 lib/timber/cli.rb
timber-2.2.1 lib/timber/cli.rb
timber-2.2.0 lib/timber/cli.rb
timber-2.1.10 lib/timber/cli.rb
timber-2.1.9 lib/timber/cli.rb
timber-2.1.8 lib/timber/cli.rb