Class: PlugemsDeploy::Cli

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ Cli

Returns a new instance of Cli.



18
19
20
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
68
69
70
71
72
73
74
75
# File 'lib/plugems_deploy/cli.rb', line 18

def initialize(args = ARGV)
  @args = args
  @options = { :version => '> 0.0', :deps_only => false, :debug => false }

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

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

    opts.on("-v", "--version VERSION",
      "The gem version to use. Any valid gem spec",
      "version expression can be specified."
    ) { |value| @options[:version] = value }

    opts.on("-o", "--only-dependencies",
    "Update only gem dependencies but not itself."
    ) { @options[:deps_only] = true }
    
    opts.on("-d", "--debug",
    "Prints some additional debug information."
    ) { @options[:debug] = true }

    opts.on("-h", "--help", "Display this help message") do
      puts opts
      exit
    end

    opts.separator ""
    opts.separator "Actions -----------------------"
    opts.separator ""
    opts.separator "push -- pushes gems to the base gem server\npublish -- builds a gem from the current directory and pushes it to the base gem server\nbuild -- builds a gem from the current directory\nupdate -- updates gems from the local gem server\nget -- updates gems from the local gem server for dependencies defined in config/manifest.yml\n".split(/\n/)

    if args.empty?
      $stderr.puts opts
      exit(-1)
    else
      opts.parse!(args)
      @opts = opts
    end
  end

  if args.size < 1
    $stderr.puts @opts
    exit(-1)
  end

  @options[:action] = args.shift
  @options[:name] = args.shift

end

Instance Attribute Details

#argsObject (readonly)

The array of (unparsed) command-line options



13
14
15
# File 'lib/plugems_deploy/cli.rb', line 13

def args
  @args
end

#optionsObject (readonly)

The hash of (parsed) command-line options



16
17
18
# File 'lib/plugems_deploy/cli.rb', line 16

def options
  @options
end

Class Method Details

.execute!Object



8
9
10
# File 'lib/plugems_deploy/cli.rb', line 8

def self.execute!
  new.execute!
end

Instance Method Details

#execute!Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/plugems_deploy/cli.rb', line 77

def execute!
  begin
    process_aliases
    validate_arguments
  rescue => ex
    puts "Invalid arguments: #{ ex }"
    exit(-1)
  end
  begin
    Capistrano::CLI.new(converted_arguments).execute!
  rescue Exception => ex
    if @options[:debug]
      raise
    else
      puts "Failed to execute: #{ ex }"
      exit(-1)
    end
  end
end