Module: Rbcli::Configurate

Defined in:
lib/rbcli/autoupdate/autoupdate.rb,
lib/rbcli/configuration/configurate.rb,
lib/rbcli/stateful_systems/configuratestorage.rb

Overview

RBCli -- A framework for developing command line applications in Ruby # Copyright (C) 2018 Andrew Khoury # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/. # # For questions regarding licensing, please contact [email protected] #

Class Method Summary collapse

Class Method Details

.allow_json_output(allow_json) ⇒ Object



83
84
85
# File 'lib/rbcli/configuration/configurate.rb', line 83

def self.allow_json_output allow_json
	@data[:allow_json] = allow_json
end

.autoupdate(gem: nil, github_repo: nil, access_token: nil, enterprise_hostname: nil, force_update: false, message: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rbcli/autoupdate/autoupdate.rb', line 22

def self.autoupdate gem: nil, github_repo: nil, access_token: nil, enterprise_hostname: nil, force_update: false, message: nil
	raise StandardError.new "Autoupdater can not have both a gem and git target defined. Please pick one." if gem and github_repo
	raise StandardError.new "Only one autoupdater can be defined." if @data[:autoupdater]
	if gem
		#Rbcli::Autoupdate::GemUpdater.save_defaults
		@data[:autoupdater] = Rbcli::Autoupdate::GemUpdater.new gem, force_update, message
	else
		Rbcli::Autoupdate::GithubUpdater.save_defaults
		@data[:autoupdater] = Rbcli::Autoupdate::GithubUpdater.new github_repo, access_token, enterprise_hostname, force_update, message
	end
	@data[:autoupdater].show_message if @data[:autoupdater].update_available?
end

.config_default(*params) ⇒ Object



79
80
81
# File 'lib/rbcli/configuration/configurate.rb', line 79

def self.config_default *params
	Rbcli::Config::add_default *params
end

.config_defaults(filename) ⇒ Object



75
76
77
# File 'lib/rbcli/configuration/configurate.rb', line 75

def self.config_defaults filename
	Rbcli::Config::add_defaults filename
end

.config_userfile(*params) ⇒ Object



70
71
72
73
# File 'lib/rbcli/configuration/configurate.rb', line 70

def self.config_userfile *params
	Rbcli::Config::set_userfile *params
	@data[:config_userfile] = params[0]
end

.configuration ⇒ Object

Data Retrieval



119
120
121
# File 'lib/rbcli/configuration/configurate.rb', line 119

def self.configuration
	@data
end

.default_action(&block) ⇒ Object



99
100
101
# File 'lib/rbcli/configuration/configurate.rb', line 99

def self.default_action &block
	@data[:default_action] = block
end

.description(desc) ⇒ Object



58
59
60
# File 'lib/rbcli/configuration/configurate.rb', line 58

def self.description desc
	@data[:description] = desc
end

.first_run(halt_after_running: false, &block) ⇒ Object



111
112
113
114
# File 'lib/rbcli/configuration/configurate.rb', line 111

def self.first_run halt_after_running: false, &block
	@data[:halt_after_first_run] = halt_after_running
	@data[:first_run] = block
end

.log_level(level) ⇒ Object



62
63
64
# File 'lib/rbcli/configuration/configurate.rb', line 62

def self.log_level level
	Rbcli::Logger::save_defaults level: level
end

.log_target(target) ⇒ Object



66
67
68
# File 'lib/rbcli/configuration/configurate.rb', line 66

def self.log_target target
	Rbcli::Logger::save_defaults target: target
end

.me(&block) ⇒ Object



38
39
40
41
# File 'lib/rbcli/configuration/configurate.rb', line 38

def self.me &block
	@self_before_instance_eval = eval "self", block.binding
	instance_eval &block
end

.option(name, description, short: nil, type: :boolean, default: nil, required: false, permitted: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rbcli/configuration/configurate.rb', line 87

def self.option name, description, short: nil, type: :boolean, default: nil, required: false, permitted: nil
	default ||= false if (type == :boolean || type == :bool || type == :flag)
	@data[:options][name.to_sym] = {
			description: description,
			type: type,
			default: default,
			required: required,
			permitted: permitted,
			short: short
	}
end

.post_hook(&block) ⇒ Object



107
108
109
# File 'lib/rbcli/configuration/configurate.rb', line 107

def self.post_hook &block
	@data[:post_hook] = block
end

.pre_hook(&block) ⇒ Object



103
104
105
# File 'lib/rbcli/configuration/configurate.rb', line 103

def self.pre_hook &block
	@data[:pre_hook] = block
end

.scriptname(name) ⇒ Object

DSL Functions



50
51
52
# File 'lib/rbcli/configuration/configurate.rb', line 50

def self.scriptname name
	@data[:scriptname] = name
end

.storage(&block) ⇒ Object



22
23
24
# File 'lib/rbcli/stateful_systems/configuratestorage.rb', line 22

def self.storage &block
	Rbcli::ConfigurateStorage.configure &block
end

.version(vsn) ⇒ Object



54
55
56
# File 'lib/rbcli/configuration/configurate.rb', line 54

def self.version vsn
	@data[:version] = vsn
end