Class: Audiobank::Client::CLI
- Inherits:
-
Object
- Object
- Audiobank::Client::CLI
- Defined in:
- lib/audiobank/client/cli.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #account ⇒ Object
- #command ⇒ Object
- #debug? ⇒ Boolean
- #import ⇒ Object
- #init ⇒ Object
-
#initialize(arguments = []) ⇒ CLI
constructor
A new instance of CLI.
- #options ⇒ Object
- #parser ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(arguments = []) ⇒ CLI
Returns a new instance of CLI.
6 7 8 |
# File 'lib/audiobank/client/cli.rb', line 6 def initialize(arguments = []) @arguments = arguments end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/audiobank/client/cli.rb', line 4 def arguments @arguments end |
#output ⇒ Object
Returns the value of attribute output.
10 11 12 |
# File 'lib/audiobank/client/cli.rb', line 10 def output @output end |
Instance Method Details
#account ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/audiobank/client/cli.rb', line 71 def account Audiobank::Account.base_uri [:base_uri] if [:base_uri] if [:token] Audiobank::Account.new([:token]) else raise "No information to connect Audiobank account" end end |
#command ⇒ Object
49 50 51 |
# File 'lib/audiobank/client/cli.rb', line 49 def command arguments.shift end |
#debug? ⇒ Boolean
37 38 39 |
# File 'lib/audiobank/client/cli.rb', line 37 def debug? [:debug] end |
#import ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/audiobank/client/cli.rb', line 81 def import arguments.each do |filename| unless filename =~ /.audiobank$/ output.puts "Import #{filename}" Audiobank::Client::LocalFile.new(filename).import(account) end end end |
#init ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/audiobank/client/cli.rb', line 41 def init if debug? Audiobank::Client.logger = Logger.new($stderr) end account end |
#options ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/audiobank/client/cli.rb', line 61 def @options ||= parser.parse(arguments).inject({}) do |map, pair| key, value = pair unless key == :help or key.to_s.match(/_given$/) or value.blank? map[key] = value end map end end |
#parser ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/audiobank/client/cli.rb', line 15 def parser Trollop::Parser.new.tap do |parser| parser.version "AudioBank client v#{Audiobank::Client::VERSION}" parser. <<-EOS Manage your AudioBank documents Usage: audiobank [options] <command> where <command> are: import <filenames>+ : to upload or import given files in AudioBank documents where [options] are: EOS parser.opt :debug, "Enable log messages" parser.opt :token, "Audiobank API token", :type => String parser.opt :base_uri, "Change default Audiobank url", :type => String end end |
#run ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/audiobank/client/cli.rb', line 53 def run Trollop::with_standard_exception_handling(parser) do init end send command end |