Module: SshyGuy
- Extended by:
- Params, Servers
- Defined in:
- lib/sshyguy.rb,
lib/sshyguy/cli.rb,
lib/sshyguy/config.rb,
lib/sshyguy/params.rb,
lib/sshyguy/prompt.rb,
lib/sshyguy/screen.rb,
lib/sshyguy/server.rb,
lib/sshyguy/command.rb,
lib/sshyguy/servers.rb,
lib/sshyguy/version.rb,
lib/sshyguy/screens/help_screen.rb,
lib/sshyguy/screens/main_screen.rb,
lib/sshyguy/screens/folder_screen.rb,
lib/sshyguy/screens/shortcut_screen.rb
Defined Under Namespace
Modules: Params, Screens, Servers
Classes: CLI, Command, Config, Error, Prompt, Screen, Server
Constant Summary
collapse
- VERSION =
'0.1.9'
- CONFIG_VERSION =
1
Class Method Summary
collapse
Methods included from Servers
servers, servers=
Methods included from Params
params, params=, reload_params!
Class Method Details
.config ⇒ Object
25
26
27
|
# File 'lib/sshyguy.rb', line 25
def self.config
configuration
end
|
.config_file ⇒ Object
36
37
38
|
# File 'lib/sshyguy.rb', line 36
def self.config_file
File.expand_path('~/.sshyguy.json')
end
|
.configuration ⇒ Object
21
22
23
|
# File 'lib/sshyguy.rb', line 21
def self.configuration
@configuration ||= Config.new
end
|
.load_config! ⇒ Object
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
|
# File 'lib/sshyguy.rb', line 40
def self.load_config!
SshyGuy.log("Checking if config_file exists at #{config_file}")
unless File.exist?(config_file)
SshyGuy.log('config_file not found')
puts "No config file found at #{config_file}"
puts 'Install this with sshyguy --install'
SshyGuy.log('Exiting program')
exit
end
begin
SshyGuy.log('Parsing config_file')
file = File.read(config_file)
SshyGuy.log('File read')
SshyGuy.log('File contents:')
SshyGuy.log(file)
SshyGuy.log('Parsing file')
json = JSON.parse(file)
if json['version'].to_i < SshyGuy::CONFIG_VERSION
puts 'Warning: Configuration out of date.'
end
SshyGuy.log('Parsed')
SshyGuy.log('Parsed contents')
SshyGuy.log(json)
SshyGuy.log('Loading config defaults')
json['config'].each do |k, v|
SshyGuy.log("Setting default '#{k}' to '#{v}'")
configuration.send("#{k}=", v)
end
json['servers'].each do |server|
if server['command'].present? || server['hostname'].present?
Server.new(server)
else
log("Skipping server #{server.inspect}")
end
end
rescue JSON::ParserError => e
puts e
puts "Unable to parse config file. Ensure it's valid JSON."
exit
end
end
|
.log(str) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/sshyguy.rb', line 29
def self.log(str)
if SshyGuy.config.debug?
puts str
puts caller(0)
end
end
|