Class: Backup::CLI

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

Overview

The CLI class encapsulates the behavior of backup when it is invoked as a command-line utility.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Docs for creating a new instance go here



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/backup/cli.rb', line 21

def initialize(args = ARGV)
  @args = args
  @options = { :recipes => [], :actions  => [], 
                  :vars => {}, # :pre_vars => {}, 
                :global => nil  }

  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"

    opts.separator ""
    opts.separator "Recipe Options -----------------------"
    opts.separator ""

    opts.on("-r", "--recipe RECIPE ",
      "A recipe file to load. Multiple recipes is DEPRECATED and not fully functional."
    ) { |value| @options[:recipes] << value }

    opts.on("-s", "--set NAME=VALUE",
      "Specify a variable and it's value to set. This",
      "will be set after loading all recipe files."
    ) do |pair|
      name, value = pair.split(/=/, 2)
      @options[:vars][name.to_sym] = value
    end

    opts.on("-g", "--global RECIPE",
      "Specify a specific file to load as the global file",
      "for the recipes. By default the recipes load the",
      "file +global.rb+ in the same directory." 
    ) { |value| @options[:recipes] << value }

    opts.on("-q", "--quiet",
          "suppresses much of the output of backup, except",
          "for error messages") { verbose(false) }

    if args.empty?
      puts opts
      exit
    else
      opts.parse!(args)
    end

    check_options!

  end

end

Instance Attribute Details

#argsObject (readonly)

The array of (unparsed) command-line options



15
16
17
# File 'lib/backup/cli.rb', line 15

def args
  @args
end

#optionsObject (readonly)

The hash of (parsed) command-line options



18
19
20
# File 'lib/backup/cli.rb', line 18

def options
  @options
end

Class Method Details

.execute!Object

Invoke capistrano using the ARGV array as the option parameters.



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

def self.execute!
  new.execute!
end

Instance Method Details

#execute!Object

Begin running Backup based on the configured options.



70
71
72
73
74
75
76
# File 'lib/backup/cli.rb', line 70

def execute!
  #if !@options[:recipes].empty? # put backk
    execute_recipes!
  # elsif @options[:apply_to]
  #  execute_apply_to!
  #end
end