Module: Rbcli

Defined in:
lib/rbcli.rb,
lib/rbcli/version.rb,
lib/rbcli/engine/parser.rb,
lib/rbcli/features/logging.rb,
lib/rbcli/engine/load_project.rb,
lib/rbcli/features/userconfig.rb,
lib/rbcli/state_storage/localstate.rb,
lib/rbcli/configuration/configurate.rb,
lib/rbcli/state_storage/placeholders.rb,
lib/rbcli/state_storage/remotestate_dynamodb.rb

Overview

User Interface

Defined Under Namespace

Modules: Autoupdate, CmdLibrary, Config, Configurable, Configurate, Logger, Msg, Parser, State Classes: Command, DeprecationWarning, RemoteExec, Scriptwrapper

Constant Summary collapse

VERSION =
'0.2.9'

Class Method Summary collapse

Class Method Details

.configObject



54
55
56
# File 'lib/rbcli/features/userconfig.rb', line 54

def self.config
	Rbcli::Config::config
end

.configuration(mod, key = nil) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/rbcli/configuration/configurate.rb', line 77

def self.configuration mod, key = nil
	begin
		d = Rbcli::Configurate.const_get(mod.to_s.capitalize.to_sym).data
		(key.nil?) ? d : d[key]
	rescue
		nil
	end
end

.debug(obj) ⇒ Object



95
96
97
# File 'lib/rbcli/features/logging.rb', line 95

def self.debug obj
	puts obj.to_s.red
end

.load_projectObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rbcli/engine/load_project.rb', line 23

def self.load_project
	project_root = File.expand_path("#{File.dirname(caller[0].split(':')[0])}/../")

	# Add lib to the load path for the user's convenience
	lib = "#{project_root}/lib"
	$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

	# We require all ruby files as-is
	%w(config hooks application application/commands).each do |dir|
		dirpath = "#{project_root}/#{dir}"
		Dir.glob "#{dirpath}/*.rb" do |file|
			require file
		end if Dir.exists? dirpath
	end

	# We automatically pull in default user configs
	configspath = "#{project_root}/userconf"
	Dir.glob "#{configspath}/*.{yml,yaml,json}" do |file|
		Rbcli::Configurate.me {config_defaults file}
	end

end

.local_stateObject



27
28
29
# File 'lib/rbcli/state_storage/localstate.rb', line 27

def self.local_state
	Rbcli.configuration(:storage, :localstate)
end

.logObject



91
92
93
# File 'lib/rbcli/features/logging.rb', line 91

def self.log
	Rbcli::Logger::log
end

.parseObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rbcli/engine/parser.rb', line 96

def self.parse
	first_run_hook = Rbcli.configuration(:me, :first_run) || Rbcli.configuration(:hooks, :first_run)
	if first_run_hook
		if Rbcli.local_state
			if Rbcli.local_state.rbclidata.key? :first_run
				Rbcli::Parser::parse
			else
				first_run_hook.call
				Rbcli.local_state.set_rbclidata :first_run, true
				Rbcli::Parser::parse unless Rbcli.configuration(:me, :halt_after_first_run) or Rbcli.configuration(:hooks, :halt_after_first_run)
			end
		else
			raise StandardError.new "Error: Can not use `first_run` without also configuring `local_state`."
		end
	else
		Rbcli::Parser::parse
	end
end

.remote_stateObject



26
27
28
# File 'lib/rbcli/state_storage/placeholders.rb', line 26

def self.remote_state
	raise Exception.new "Warning: Usage of Remote State requires Remote State Storage to be enabled in your application's configuration."
end