This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
/
base.rb
89 lines (75 loc) · 2.57 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'commander'
require 'commander/delegates'
require 'rhc/helpers'
class RHC::Commands::Base
def initialize(args=[], options=OptionParser.new)
@args, @options = args, options
end
protected
include RHC::Helpers
attr_reader :args, :options
def application
#@application ||= ... identify current application or throw,
# indicating one is needed. Should check
# options (commands which have it as an ARG
# should set it onto options), then check
# current git repo for remote, fail.
end
def client
#@client ||= ... Return a client object capable of making calls
# to the OpenShift API that transforms intent
# and options, to remote calls, and then handle
# the output (or failures) into exceptions and
# formatted object output. Most interactions
# should be through this call pattern.
#
# Initialize with auth (a separate responsibility
# object).
end
def config
@config ||= begin
RHC::Config.set_opts_config(options.config) if options.config
RHC::Config.password = options.password if options.password
RHC::Config.opts_login = options.rhlogin if options.rhlogin
RHC::Config
end
end
class InvalidCommand < StandardError ; end
def self.inherited(klass)
unless klass == RHC::Commands::Base
end
end
def self.method_added(method)
return if self == RHC::Commands::Base
return if private_method_defined? method
return if protected_method_defined? method
method_name = method.to_s == 'run' ? nil : method.to_s
name = [method_name]
name.unshift(self.object_name).compact!
raise InvalidCommand, "Either object_name must be set or a non default method defined" if name.empty?
RHC::Commands.add((@options || {}).merge({
:name => name.join(' '),
:class => self,
:method => method,
}));
@options = nil
end
def self.object_name(value=nil)
@object_name ||= begin
value ||= if self.name && !self.name.empty?
self.name.split('::').last
end
value.to_s.downcase if value
end
end
def self.description(value)
options[:description] = value
end
def self.summary(value)
options[:summary] = value
end
private
def self.options
@options ||= {}
end
end