Class: Rbk::Cli

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

Defined Under Namespace

Classes: Archiver

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, options = {}) ⇒ Cli

Returns a new instance of Cli.



9
10
11
12
13
14
15
# File 'lib/rbk/cli.rb', line 9

def initialize(argv, options={})
  @argv = argv
  @options = options
  @git = @options[:git] || Git
  @github_repos = @options[:github_repos] || Github::Repos
  @stderr = @options[:stderr] || $stderr
end

Class Method Details

.run(argv = ARGV, options = {}) ⇒ Object



5
6
7
# File 'lib/rbk/cli.rb', line 5

def self.run(argv=ARGV, options={})
  new(argv, options).run
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rbk/cli.rb', line 17

def run
  @config = Configuration.create(@argv)
  @config.validate
  @shell = @options[:shell] || Shell.new(@config.quiet?)
  @archiver = Archiver.new(@shell)
  @s3 = @options[:s3] || AWS::S3.new(@config.aws_credentials)
  @uploader = Uploader.new(@s3.buckets[@config.bucket], @shell)
  if @config.help?
    @shell.puts(@config.usage)
  else
    Backup.new(repos, git, archiver, uploader, shell).run
  end
  0
rescue => e
  @stderr.puts(%(#{e.message} (#{e.class})))
  if e.is_a?(InsufficientOptionsError)
    @stderr.puts(@config.usage)
  end
  1
end