configliere 0.3.4 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.watchr +20 -0
- data/CHANGELOG.textile +99 -3
- data/Gemfile +26 -0
- data/Gemfile.lock +54 -0
- data/README.textile +162 -138
- data/Rakefile +30 -21
- data/VERSION +1 -1
- data/bin/configliere +77 -77
- data/bin/configliere-decrypt +85 -0
- data/bin/configliere-delete +85 -0
- data/bin/configliere-dump +85 -0
- data/bin/configliere-encrypt +85 -0
- data/bin/configliere-list +85 -0
- data/bin/configliere-set +85 -0
- data/configliere.gemspec +53 -23
- data/examples/config_block_script.rb +9 -2
- data/examples/encrypted_script.rb +28 -16
- data/examples/env_var_script.rb +2 -2
- data/examples/help_message_demo.rb +16 -0
- data/examples/independent_config.rb +28 -0
- data/examples/prompt.rb +23 -0
- data/examples/simple_script.rb +28 -15
- data/examples/simple_script.yaml +1 -1
- data/lib/configliere.rb +22 -24
- data/lib/configliere/commandline.rb +135 -116
- data/lib/configliere/commands.rb +38 -54
- data/lib/configliere/config_block.rb +4 -2
- data/lib/configliere/config_file.rb +30 -52
- data/lib/configliere/crypter.rb +8 -5
- data/lib/configliere/deep_hash.rb +368 -0
- data/lib/configliere/define.rb +83 -89
- data/lib/configliere/encrypted.rb +17 -18
- data/lib/configliere/env_var.rb +5 -7
- data/lib/configliere/param.rb +37 -64
- data/lib/configliere/prompt.rb +23 -0
- data/spec/configliere/commandline_spec.rb +156 -57
- data/spec/configliere/commands_spec.rb +75 -30
- data/spec/configliere/config_block_spec.rb +10 -1
- data/spec/configliere/config_file_spec.rb +83 -55
- data/spec/configliere/crypter_spec.rb +3 -2
- data/spec/configliere/deep_hash_spec.rb +401 -0
- data/spec/configliere/define_spec.rb +121 -42
- data/spec/configliere/encrypted_spec.rb +53 -20
- data/spec/configliere/env_var_spec.rb +24 -4
- data/spec/configliere/param_spec.rb +25 -27
- data/spec/configliere/prompt_spec.rb +50 -0
- data/spec/configliere_spec.rb +3 -9
- data/spec/spec_helper.rb +17 -6
- metadata +110 -35
- data/lib/configliere/core_ext.rb +0 -2
- data/lib/configliere/core_ext/blank.rb +0 -93
- data/lib/configliere/core_ext/hash.rb +0 -108
- data/lib/configliere/core_ext/sash.rb +0 -170
- data/spec/configliere/core_ext/hash_spec.rb +0 -78
- data/spec/configliere/core_ext/sash_spec.rb +0 -312
data/Rakefile
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
2
10
|
require 'rake'
|
3
11
|
|
4
12
|
begin
|
5
13
|
require 'jeweler'
|
6
14
|
Jeweler::Tasks.new do |gem|
|
7
15
|
gem.name = "configliere"
|
16
|
+
gem.homepage = "http://infochimps.com/labs"
|
17
|
+
gem.license = "MIT"
|
8
18
|
gem.summary = %Q{Wise, discreet configuration management}
|
9
19
|
gem.description = %Q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
10
20
|
|
@@ -12,41 +22,40 @@ begin
|
|
12
22
|
|
13
23
|
Configliere manage settings from many sources: static constants, simple config files, environment variables, commandline options, straight ruby. You don't have to predefine anything, but you can ask configliere to type-convert, require, document or password-obscure any of its fields. Modules can define config settings independently of each other and the main program.
|
14
24
|
} #'
|
15
|
-
gem.email = "
|
16
|
-
gem.
|
17
|
-
gem.authors = ["mrflip"]
|
18
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
19
|
-
gem.add_development_dependency "yard", ">= 0"
|
20
|
-
# gem.add_dependency "highline", ">= 0"
|
21
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
25
|
+
gem.email = "coders@infochimps.org"
|
26
|
+
gem.authors = ["infochimps", "mrflip"]
|
22
27
|
end
|
23
|
-
Jeweler::
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
24
29
|
rescue LoadError
|
25
30
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
26
31
|
end
|
27
32
|
|
28
|
-
begin
|
29
|
-
require 'spec/rake/spectask'
|
30
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
32
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
-
end
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
require 'rspec/core'
|
35
|
+
require 'rspec/core/rake_task'
|
36
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
37
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
#
|
42
|
+
# if rcov shits the bed with ruby 1.9, see
|
43
|
+
# https://github.com/relevance/rcov/issues/31
|
44
|
+
#
|
45
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
46
|
spec.pattern = 'spec/**/*_spec.rb'
|
38
47
|
spec.rcov = true
|
48
|
+
spec.rcov_opts = %w[ --exclude .rvm --no-comments --text-summary]
|
39
49
|
end
|
40
|
-
task :spec => :check_dependencies
|
41
50
|
rescue LoadError
|
42
|
-
task :
|
43
|
-
abort "
|
51
|
+
task :rspec do
|
52
|
+
abort "Rspec is not available. In order to run spec, you must: sudo gem install rspec"
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
47
56
|
begin
|
48
|
-
require 'reek/
|
49
|
-
Reek::
|
57
|
+
require 'reek/rake/task'
|
58
|
+
Reek::Rake::Task.new do |t|
|
50
59
|
t.fail_on_error = true
|
51
60
|
t.verbose = false
|
52
61
|
t.source_files = 'lib/**/*.rb'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.4
|
data/bin/configliere
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$: << File.dirname(__FILE__)+'/../lib'
|
3
3
|
require 'configliere'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
|
5
|
+
Settings.use :commands
|
6
|
+
|
7
|
+
Settings.description = %Q{Client for the configliere gem: manipulate configuration and passwords for automated scripts}
|
8
|
+
|
9
|
+
Settings.define_command :dump, :description => "Show the whole contents of the file"
|
10
|
+
Settings.define_command :list, :description => "Show all params in the configliere file."
|
11
|
+
Settings.define_command :get, :description => "show values given as commandline args, eg: #{File.basename($0)} get this that"
|
12
|
+
Settings.define_command :set, :description => "sets values given as commandline args, eg: #{File.basename($0)} set this=1 that=3"
|
13
|
+
Settings.define_command :delete, :description => "sets values given as commandline args, eg: #{File.basename($0)} delete this that"
|
14
|
+
Settings.define_command :encrypt, :description => "encrypt the param"
|
15
|
+
Settings.define_command :decrypt, :description => "Store the param as decrypted back into the file. Can be undone with 'encrypt'."
|
16
|
+
|
17
|
+
Settings.define :from, :flag => 'f', :type => :filename, :description => "Configliere config file to load"
|
18
|
+
Settings.define :into, :flag => 'i', :type => :filename, :description => "Configliere config file to save into"
|
19
|
+
|
20
|
+
Settings.resolve!
|
21
|
+
ARGV.replace []
|
22
|
+
|
23
|
+
Store = Configliere.new
|
24
|
+
Store.read(Settings.from) if Settings.from
|
25
|
+
|
26
|
+
#
|
27
|
+
# Execute
|
28
|
+
#
|
29
|
+
|
30
|
+
case Settings.command_name
|
31
|
+
when :dump
|
32
|
+
puts Store.to_hash.to_yaml
|
33
|
+
|
34
|
+
when :list
|
35
|
+
$stderr.puts "Param names in #{Settings.from}:"
|
36
|
+
Store.each do |attr, val|
|
37
|
+
puts " #{attr}"
|
24
38
|
end
|
25
39
|
|
40
|
+
when :get
|
41
|
+
$stderr.puts "Values for #{Settings.rest.join(", ")} from #{Settings.from}"
|
42
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
43
|
+
puts "%-23s\t%s" % ["#{attr}:", Store[attr]]
|
44
|
+
end
|
45
|
+
|
46
|
+
when :set
|
47
|
+
$stderr.puts "Setting #{Settings.rest.join(", ")} for #{Settings.from}"
|
48
|
+
Settings.rest.each do |attr_val|
|
49
|
+
attr, val = attr_val.split('=', 2)
|
50
|
+
attr = attr.to_sym
|
51
|
+
if val.nil? then warn "Please specify a value for #{attr}" ; next ; end
|
52
|
+
Store[attr] = val
|
26
53
|
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
store.fix!(handle, option_or_ask(:key))
|
36
|
-
end
|
37
|
-
COMMANDS[:encrypt] = "synonym for fix. Params are stored encrypted by default"
|
38
|
-
def encrypt() fix end
|
39
|
-
|
40
|
-
COMMANDS[:decrypt] = "Store the param as decrypted back into the file. Can be undone with 'fix'."
|
41
|
-
def decrypt
|
42
|
-
Log.info "Storing info for #{handle} in **DECRYPTED** form."
|
43
|
-
param = get(handle)
|
44
|
-
store.put_decrypted!(handle, param)
|
45
|
-
end
|
46
|
-
|
47
|
-
COMMANDS[:list] = "Show all params in the configliere file."
|
48
|
-
def list
|
49
|
-
puts "List of param names: #{store.handles.inspect}"
|
50
|
-
end
|
51
|
-
|
52
|
-
COMMANDS[:delete] = "Permanently deletes the param"
|
53
|
-
def delete
|
54
|
-
Log.info "Permanently deleting stored info for #{handle}. O, I die, Horatio."
|
55
|
-
store.delete! handle, options[:key]
|
56
|
-
end
|
57
|
-
|
58
|
-
COMMANDS[:set] = "sets values using remaining arguments from the command line. eg #{File.basename($0)} set my_program --username=bob --password=frank"
|
59
|
-
def set
|
60
|
-
param = get(handle)
|
61
|
-
param.merge! external_options
|
62
|
-
store.put handle, param
|
63
|
-
store.save!
|
64
|
-
Log.info "Stored configuration for #{handle}: #{param}"
|
65
|
-
end
|
66
|
-
|
67
|
-
COMMANDS[:change_key] = "set a new key and/or new key options. Specify the old key as usual with --key='...' and the new one with --new_key='...'"
|
68
|
-
def change_key
|
69
|
-
param = get(handle)
|
70
|
-
new_key = option_or_ask(:new_key)
|
71
|
-
new_hsh = param.to_decrypted
|
72
|
-
new_param = Configliere::Param.new(new_key, new_hsh)
|
73
|
-
store.put! handle, new_param
|
74
|
-
Log.info "Changed param key for #{handle}: #{new_param}"
|
75
|
-
end
|
76
|
-
|
77
|
-
COMMANDS[:show] = "print the decrypted information"
|
78
|
-
def show
|
79
|
-
param = get(handle)
|
80
|
-
puts "Stored info for #{handle}:\n #{param.to_s}"
|
81
|
-
end
|
54
|
+
puts "%-23s\t%s" % ["#{attr}:", val.inspect]
|
55
|
+
end
|
56
|
+
|
57
|
+
when :delete
|
58
|
+
$stderr.puts "Deleting #{Settings.rest.join(", ")} from #{Settings.from}. O, I die, Horatio."
|
59
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
60
|
+
Store.delete(attr)
|
61
|
+
end
|
82
62
|
|
63
|
+
when :encrypt
|
64
|
+
Store.use :encrypted
|
65
|
+
$stderr.puts "Encrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
66
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
67
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
68
|
+
Store.resolve!
|
69
|
+
|
70
|
+
when :decrypt
|
71
|
+
Store.use :encrypted
|
72
|
+
$stderr.puts "Decrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
73
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
74
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
75
|
+
Store.resolve!
|
76
|
+
|
77
|
+
puts Store.to_hash.to_yaml
|
78
|
+
|
79
|
+
else
|
80
|
+
Settings.die "Please use one of the given commands"
|
83
81
|
end
|
84
82
|
|
85
|
-
|
83
|
+
if Settings.into
|
84
|
+
Store.save!(Settings.into)
|
85
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.dirname(__FILE__)+'/../lib'
|
3
|
+
require 'configliere'
|
4
|
+
|
5
|
+
Settings.use :commands
|
6
|
+
|
7
|
+
Settings.description = %Q{Client for the configliere gem: manipulate configuration and passwords for automated scripts}
|
8
|
+
|
9
|
+
Settings.define_command :dump, :description => "Show the whole contents of the file"
|
10
|
+
Settings.define_command :list, :description => "Show all params in the configliere file."
|
11
|
+
Settings.define_command :get, :description => "show values given as commandline args, eg: #{File.basename($0)} get this that"
|
12
|
+
Settings.define_command :set, :description => "sets values given as commandline args, eg: #{File.basename($0)} set this=1 that=3"
|
13
|
+
Settings.define_command :delete, :description => "sets values given as commandline args, eg: #{File.basename($0)} delete this that"
|
14
|
+
Settings.define_command :encrypt, :description => "encrypt the param"
|
15
|
+
Settings.define_command :decrypt, :description => "Store the param as decrypted back into the file. Can be undone with 'encrypt'."
|
16
|
+
|
17
|
+
Settings.define :from, :flag => 'f', :type => :filename, :description => "Configliere config file to load"
|
18
|
+
Settings.define :into, :flag => 'i', :type => :filename, :description => "Configliere config file to save into"
|
19
|
+
|
20
|
+
Settings.resolve!
|
21
|
+
ARGV.replace []
|
22
|
+
|
23
|
+
Store = Configliere.new
|
24
|
+
Store.read(Settings.from) if Settings.from
|
25
|
+
|
26
|
+
#
|
27
|
+
# Execute
|
28
|
+
#
|
29
|
+
|
30
|
+
case Settings.command_name
|
31
|
+
when :dump
|
32
|
+
puts Store.to_hash.to_yaml
|
33
|
+
|
34
|
+
when :list
|
35
|
+
$stderr.puts "Param names in #{Settings.from}:"
|
36
|
+
Store.each do |attr, val|
|
37
|
+
puts " #{attr}"
|
38
|
+
end
|
39
|
+
|
40
|
+
when :get
|
41
|
+
$stderr.puts "Values for #{Settings.rest.join(", ")} from #{Settings.from}"
|
42
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
43
|
+
puts "%-23s\t%s" % ["#{attr}:", Store[attr]]
|
44
|
+
end
|
45
|
+
|
46
|
+
when :set
|
47
|
+
$stderr.puts "Setting #{Settings.rest.join(", ")} for #{Settings.from}"
|
48
|
+
Settings.rest.each do |attr_val|
|
49
|
+
attr, val = attr_val.split('=', 2)
|
50
|
+
attr = attr.to_sym
|
51
|
+
if val.nil? then warn "Please specify a value for #{attr}" ; next ; end
|
52
|
+
Store[attr] = val
|
53
|
+
|
54
|
+
puts "%-23s\t%s" % ["#{attr}:", val.inspect]
|
55
|
+
end
|
56
|
+
|
57
|
+
when :delete
|
58
|
+
$stderr.puts "Deleting #{Settings.rest.join(", ")} from #{Settings.from}. O, I die, Horatio."
|
59
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
60
|
+
Store.delete(attr)
|
61
|
+
end
|
62
|
+
|
63
|
+
when :encrypt
|
64
|
+
Store.use :encrypted
|
65
|
+
$stderr.puts "Encrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
66
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
67
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
68
|
+
Store.resolve!
|
69
|
+
|
70
|
+
when :decrypt
|
71
|
+
Store.use :encrypted
|
72
|
+
$stderr.puts "Decrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
73
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
74
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
75
|
+
Store.resolve!
|
76
|
+
|
77
|
+
puts Store.to_hash.to_yaml
|
78
|
+
|
79
|
+
else
|
80
|
+
Settings.die "Please use one of the given commands"
|
81
|
+
end
|
82
|
+
|
83
|
+
if Settings.into
|
84
|
+
Store.save!(Settings.into)
|
85
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.dirname(__FILE__)+'/../lib'
|
3
|
+
require 'configliere'
|
4
|
+
|
5
|
+
Settings.use :commands
|
6
|
+
|
7
|
+
Settings.description = %Q{Client for the configliere gem: manipulate configuration and passwords for automated scripts}
|
8
|
+
|
9
|
+
Settings.define_command :dump, :description => "Show the whole contents of the file"
|
10
|
+
Settings.define_command :list, :description => "Show all params in the configliere file."
|
11
|
+
Settings.define_command :get, :description => "show values given as commandline args, eg: #{File.basename($0)} get this that"
|
12
|
+
Settings.define_command :set, :description => "sets values given as commandline args, eg: #{File.basename($0)} set this=1 that=3"
|
13
|
+
Settings.define_command :delete, :description => "sets values given as commandline args, eg: #{File.basename($0)} delete this that"
|
14
|
+
Settings.define_command :encrypt, :description => "encrypt the param"
|
15
|
+
Settings.define_command :decrypt, :description => "Store the param as decrypted back into the file. Can be undone with 'encrypt'."
|
16
|
+
|
17
|
+
Settings.define :from, :flag => 'f', :type => :filename, :description => "Configliere config file to load"
|
18
|
+
Settings.define :into, :flag => 'i', :type => :filename, :description => "Configliere config file to save into"
|
19
|
+
|
20
|
+
Settings.resolve!
|
21
|
+
ARGV.replace []
|
22
|
+
|
23
|
+
Store = Configliere.new
|
24
|
+
Store.read(Settings.from) if Settings.from
|
25
|
+
|
26
|
+
#
|
27
|
+
# Execute
|
28
|
+
#
|
29
|
+
|
30
|
+
case Settings.command_name
|
31
|
+
when :dump
|
32
|
+
puts Store.to_hash.to_yaml
|
33
|
+
|
34
|
+
when :list
|
35
|
+
$stderr.puts "Param names in #{Settings.from}:"
|
36
|
+
Store.each do |attr, val|
|
37
|
+
puts " #{attr}"
|
38
|
+
end
|
39
|
+
|
40
|
+
when :get
|
41
|
+
$stderr.puts "Values for #{Settings.rest.join(", ")} from #{Settings.from}"
|
42
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
43
|
+
puts "%-23s\t%s" % ["#{attr}:", Store[attr]]
|
44
|
+
end
|
45
|
+
|
46
|
+
when :set
|
47
|
+
$stderr.puts "Setting #{Settings.rest.join(", ")} for #{Settings.from}"
|
48
|
+
Settings.rest.each do |attr_val|
|
49
|
+
attr, val = attr_val.split('=', 2)
|
50
|
+
attr = attr.to_sym
|
51
|
+
if val.nil? then warn "Please specify a value for #{attr}" ; next ; end
|
52
|
+
Store[attr] = val
|
53
|
+
|
54
|
+
puts "%-23s\t%s" % ["#{attr}:", val.inspect]
|
55
|
+
end
|
56
|
+
|
57
|
+
when :delete
|
58
|
+
$stderr.puts "Deleting #{Settings.rest.join(", ")} from #{Settings.from}. O, I die, Horatio."
|
59
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
60
|
+
Store.delete(attr)
|
61
|
+
end
|
62
|
+
|
63
|
+
when :encrypt
|
64
|
+
Store.use :encrypted
|
65
|
+
$stderr.puts "Encrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
66
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
67
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
68
|
+
Store.resolve!
|
69
|
+
|
70
|
+
when :decrypt
|
71
|
+
Store.use :encrypted
|
72
|
+
$stderr.puts "Decrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
73
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
74
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
75
|
+
Store.resolve!
|
76
|
+
|
77
|
+
puts Store.to_hash.to_yaml
|
78
|
+
|
79
|
+
else
|
80
|
+
Settings.die "Please use one of the given commands"
|
81
|
+
end
|
82
|
+
|
83
|
+
if Settings.into
|
84
|
+
Store.save!(Settings.into)
|
85
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.dirname(__FILE__)+'/../lib'
|
3
|
+
require 'configliere'
|
4
|
+
|
5
|
+
Settings.use :commands
|
6
|
+
|
7
|
+
Settings.description = %Q{Client for the configliere gem: manipulate configuration and passwords for automated scripts}
|
8
|
+
|
9
|
+
Settings.define_command :dump, :description => "Show the whole contents of the file"
|
10
|
+
Settings.define_command :list, :description => "Show all params in the configliere file."
|
11
|
+
Settings.define_command :get, :description => "show values given as commandline args, eg: #{File.basename($0)} get this that"
|
12
|
+
Settings.define_command :set, :description => "sets values given as commandline args, eg: #{File.basename($0)} set this=1 that=3"
|
13
|
+
Settings.define_command :delete, :description => "sets values given as commandline args, eg: #{File.basename($0)} delete this that"
|
14
|
+
Settings.define_command :encrypt, :description => "encrypt the param"
|
15
|
+
Settings.define_command :decrypt, :description => "Store the param as decrypted back into the file. Can be undone with 'encrypt'."
|
16
|
+
|
17
|
+
Settings.define :from, :flag => 'f', :type => :filename, :description => "Configliere config file to load"
|
18
|
+
Settings.define :into, :flag => 'i', :type => :filename, :description => "Configliere config file to save into"
|
19
|
+
|
20
|
+
Settings.resolve!
|
21
|
+
ARGV.replace []
|
22
|
+
|
23
|
+
Store = Configliere.new
|
24
|
+
Store.read(Settings.from) if Settings.from
|
25
|
+
|
26
|
+
#
|
27
|
+
# Execute
|
28
|
+
#
|
29
|
+
|
30
|
+
case Settings.command_name
|
31
|
+
when :dump
|
32
|
+
puts Store.to_hash.to_yaml
|
33
|
+
|
34
|
+
when :list
|
35
|
+
$stderr.puts "Param names in #{Settings.from}:"
|
36
|
+
Store.each do |attr, val|
|
37
|
+
puts " #{attr}"
|
38
|
+
end
|
39
|
+
|
40
|
+
when :get
|
41
|
+
$stderr.puts "Values for #{Settings.rest.join(", ")} from #{Settings.from}"
|
42
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
43
|
+
puts "%-23s\t%s" % ["#{attr}:", Store[attr]]
|
44
|
+
end
|
45
|
+
|
46
|
+
when :set
|
47
|
+
$stderr.puts "Setting #{Settings.rest.join(", ")} for #{Settings.from}"
|
48
|
+
Settings.rest.each do |attr_val|
|
49
|
+
attr, val = attr_val.split('=', 2)
|
50
|
+
attr = attr.to_sym
|
51
|
+
if val.nil? then warn "Please specify a value for #{attr}" ; next ; end
|
52
|
+
Store[attr] = val
|
53
|
+
|
54
|
+
puts "%-23s\t%s" % ["#{attr}:", val.inspect]
|
55
|
+
end
|
56
|
+
|
57
|
+
when :delete
|
58
|
+
$stderr.puts "Deleting #{Settings.rest.join(", ")} from #{Settings.from}. O, I die, Horatio."
|
59
|
+
Settings.rest.map(&:to_sym).each do |attr|
|
60
|
+
Store.delete(attr)
|
61
|
+
end
|
62
|
+
|
63
|
+
when :encrypt
|
64
|
+
Store.use :encrypted
|
65
|
+
$stderr.puts "Encrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
66
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
67
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
68
|
+
Store.resolve!
|
69
|
+
|
70
|
+
when :decrypt
|
71
|
+
Store.use :encrypted
|
72
|
+
$stderr.puts "Decrypting #{Settings.rest.join(", ")} from #{Settings.from}. Fnord"
|
73
|
+
Settings.rest.each{|attr| Store.define attr, :encrypted => true }
|
74
|
+
Store.encrypt_pass = Settings.encrypt_pass || Settings[:encrypt_pass]
|
75
|
+
Store.resolve!
|
76
|
+
|
77
|
+
puts Store.to_hash.to_yaml
|
78
|
+
|
79
|
+
else
|
80
|
+
Settings.die "Please use one of the given commands"
|
81
|
+
end
|
82
|
+
|
83
|
+
if Settings.into
|
84
|
+
Store.save!(Settings.into)
|
85
|
+
end
|