Class: Audiobank::Client::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/audiobank/client/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argumentsObject

Returns the value of attribute arguments.



4
5
6
# File 'lib/audiobank/client/cli.rb', line 4

def arguments
  @arguments
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/audiobank/client/cli.rb', line 10

def output
  @output
end

Instance Method Details

#accountObject



71
72
73
74
75
76
77
78
79
# File 'lib/audiobank/client/cli.rb', line 71

def 
  Audiobank::Account.base_uri options[:base_uri] if options[:base_uri]

  if options[:token]
    Audiobank::Account.new(options[:token])
  else
    raise "No information to connect Audiobank account"
  end
end

#commandObject



49
50
51
# File 'lib/audiobank/client/cli.rb', line 49

def command
  arguments.shift
end

#debug?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/audiobank/client/cli.rb', line 37

def debug?
  options[:debug]
end

#importObject



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()
    end
  end
end

#initObject



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

  
end

#optionsObject



61
62
63
64
65
66
67
68
69
# File 'lib/audiobank/client/cli.rb', line 61

def options
  @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

#parserObject



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.banner <<-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

#runObject



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