Sha256: bd121181bc67420bd89bcfedabc826fbe8fef491d6c16125eb2adc4ad973e802

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require 'rubygems'
begin
  gem 'trollop', '~> 1.16.2'
  gem 'terminal-table', '~> 1.4.2'
  require 'trollop'
  require 'terminal-table/import'
rescue LoadError
  puts "You must install the trollop gem (~> 1.16.2) and the terminal-table gem (~> 1.4.2) to use the Zencoder CLI."
  exit 1
end

require 'zencoder'
require 'zencoder/cli/helpers'
require 'zencoder/cli/auth'
require 'zencoder/cli/plugin'
require 'zencoder/cli/command'
require 'zencoder/cli/response'
ZencoderCLI::Plugin.load!

global_options = Trollop::options do
  version "Zencoder #{Zencoder::GEM_VERSION}"
  banner <<-EOS
#{"-" * (14 + Zencoder::GEM_VERSION.length)}
Zencoder CLI v#{Zencoder::GEM_VERSION}
#{"-" * (14 + Zencoder::GEM_VERSION.length)}

== Usage

zencoder [global-options] command [command-options]

== Available Commands

#{
  ZencoderCLI::Command.commands.sort.map{|group, commands|
    commands.map{|command, description|
      command.ljust(22)+" # "+(description.is_a?(String) ? description : description[:description])
    }.join("\n")
  }.join("\n\n")
}

== Global Options
EOS
  opt :environment, "Sets the environment to use (optional: defaults to production)", :type => String
  stop_on ZencoderCLI::Command.commands.map{|k, v| v.keys }.flatten
end

if ARGV.empty?
  puts "You must specify a command. Use --help for more information."
  exit(1)
end

command = ARGV.shift.strip
args = ARGV


flat_commands = ZencoderCLI::Command.commands.values.inject({}){|memo,group| memo.merge!(group) }
command_options = Trollop::options do
  banner <<-EOS
== Usage

zencoder [global-options] #{command} [options]

== Command Options
EOS
  if flat_commands[command] && flat_commands[command][:options]
    flat_commands[command][:options].call(self)
  end
end


ZencoderCLI::Command.run(command, args, global_options, command_options)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zencoder-2.2.2 lib/zencoder/cli.rb