Class: Jenkins2::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/jenkins2/cli.rb,
lib/jenkins2/cli/job.rb,
lib/jenkins2/cli/root.rb,
lib/jenkins2/cli/user.rb,
lib/jenkins2/cli/view.rb,
lib/jenkins2/cli/nodes.rb,
lib/jenkins2/cli/plugins.rb,
lib/jenkins2/cli/credentials.rb,
lib/jenkins2/cli/role_strategy.rb

Defined Under Namespace

Classes: AddJobToView, AssignRole, CancelQuietDown, ConnectNode, CopyJob, CreateCredentialsByXml, CreateCredentialsDomainByXml, CreateJob, CreateNode, CreateRole, CreateView, DeleteCredentials, DeleteCredentialsDomain, DeleteJob, DeleteNode, DeleteRoles, DeleteView, DisableJob, DisconnectNode, EnableJob, GetCredentialsAsXml, GetCredentialsDomainAsXml, GetJob, GetNode, GetView, InstallPlugin, ListCredentials, ListJobs, ListNode, ListOnlineNode, ListPlugins, ListRoles, OfflineNode, OnlineNode, QuietDown, RemoveJobFromView, Restart, SafeRestart, ShowPlugin, UnassignAllRoles, UnassignRole, UninstallPlugin, UpdateCredentialsByXml, UpdateCredentialsDomainByXml, UpdateJob, UpdateNode, UpdateView, Version, WaitNodeOffline, WaitNodeOnline, WhoAmI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



20
21
22
23
24
25
26
# File 'lib/jenkins2/cli.rb', line 20

def initialize(options={})
	@options = options.dup
	@command = []
	@errors = []
	@parser = nil
	add_options
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.class_to_commandObject



54
55
56
# File 'lib/jenkins2/cli.rb', line 54

def self.class_to_command
	to_s.split('::').last.gsub(/(.)([A-Z])/, '\1-\2').downcase if superclass == Jenkins2::CLI
end

.descriptionObject

This method should be overwritten in subclasses



52
# File 'lib/jenkins2/cli.rb', line 52

def self.description; end

.subcommandsObject



58
59
60
61
62
# File 'lib/jenkins2/cli.rb', line 58

def self.subcommands
	constants(false).collect{|c| const_get(c) }.select do |c|
		c.is_a?(Class) and c.superclass == Jenkins2::CLI
	end.sort_by(&:to_s)
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jenkins2/cli.rb', line 28

def call
	if options[:help]
		summary
	elsif options[:version]
		Jenkins2::VERSION
	elsif !errors.empty?
		errors.join("\n") + "\n" + summary
	else
		run
	end
end

#parse(args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/jenkins2/cli.rb', line 40

def parse(args)
	parser.order! args do |nonopt|
		@command << nonopt
		return command_to_class.new(options).parse(args) if command_to_class
		next
	end
	missing = mandatory_arguments.select{|a| options[a].nil? }
	@errors << "Missing argument(s): #{missing.join(', ')}." unless missing.empty?
	self
end