Class: Chef::Knife::ScribeHire
- Inherits:
-
Chef::Knife
show all
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/knife/scribe_hire.rb
Constant Summary
collapse
- DEFAULT_CHRONICLE_PATH =
".chronicle"
- DEFAULT_REMOTE_NAME =
"origin"
Instance Method Summary
collapse
Methods inherited from Chef::Knife
#deep_delete, #deep_delete!, #diff
Instance Method Details
61
62
63
64
65
66
67
68
|
# File 'lib/chef/knife/scribe_hire.rb', line 61
def configure
conf = { :chronicle_path => DEFAULT_CHRONICLE_PATH,
:remote_name => DEFAULT_REMOTE_NAME }
conf.merge!(Chef::Config[:knife][:scribe]) if Chef::Config[:knife][:scribe].kind_of? Hash
conf.each do |key, value|
config[key] ||= value
end
end
|
#init_chronicle ⇒ Object
70
71
72
|
# File 'lib/chef/knife/scribe_hire.rb', line 70
def init_chronicle
shell_out!("git init", { :cwd => config[:chronicle_path] })
end
|
#run ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/chef/knife/scribe_hire.rb', line 50
def run
configure
Dir.mkdir(config[:chronicle_path]) unless File.directory?(config[:chronicle_path])
init_chronicle
setup_remote if config[:remote_url]
["environments", "nodes", "roles"].each do |dir|
path = File.join(config[:chronicle_path], dir)
Dir.mkdir(path) unless File.directory?(path)
end
end
|
#setup_remote ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/chef/knife/scribe_hire.rb', line 74
def setup_remote
check_remote_command = "git config --get remote.#{config[:remote_name]}.url"
remote_status = shell_out!(check_remote_command, { :cwd => config[:chronicle_path], :returns => [0,1,2] })
case remote_status.exitstatus
when 0, 2
unless remote_status.exitstatus != 2 && remote_status.stdout.strip.eql?(config[:remote_url])
update_remote_url_command = "git config --replace-all remote.#{config[:remote_name]}.url #{config[:remote_url]}"
shell_out!(update_remote_url_command, { :cwd => config[:chronicle_path] })
end
when 1
add_remote_command = "git remote add #{config[:remote_name]} #{config[:remote_url]}"
shell_out!(add_remote_command, { :cwd => config[:chronicle_path] })
end
end
|