confgen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/confgen +6 -0
- data/lib/confgen.rb +52 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f821a02c98c4fa3a90bcc5d7beb1315b2f890165
|
4
|
+
data.tar.gz: 15b2c52c1a8ca3cf088d1f73e877ba362d7cad61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e106e6172570a352b3d7503bbaefe82589e2e502a5df13409eb5a849b6d85d3be081111211f675d927d47869b195780df8856b03659c440bc7893d93107b3e93
|
7
|
+
data.tar.gz: ab17bb8fbca3facf44d489b81f4b93a49bddc2afefc614cee8504bfbd12aa99dde387fb518c3ce4f3004e5175fd6aca0133052a21539aaa61ba387e0b7b82cc0
|
data/bin/confgen
ADDED
data/lib/confgen.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require("highline/import")
|
3
|
+
require("yaml")
|
4
|
+
require("erb")
|
5
|
+
|
6
|
+
class ConfGen
|
7
|
+
def generate()
|
8
|
+
config = YAML::load(File.open('.confgen'))
|
9
|
+
template = config['template']
|
10
|
+
destination = config['destination']
|
11
|
+
data = gather(config)
|
12
|
+
|
13
|
+
say("Generation will continue with the following data")
|
14
|
+
say(data)
|
15
|
+
|
16
|
+
if (agree("Continue [y/n]?", true))
|
17
|
+
tpl = ERB.new(File.read(template))
|
18
|
+
|
19
|
+
File.open(destination, 'w') do |f|
|
20
|
+
f.write(tpl.result(binding))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def gather(config)
|
26
|
+
data = Hash.new()
|
27
|
+
|
28
|
+
config['variables'].each do |var|
|
29
|
+
data[var['name']] = self.send(var['type'], var)
|
30
|
+
end
|
31
|
+
|
32
|
+
return data
|
33
|
+
end
|
34
|
+
|
35
|
+
def choice(var)
|
36
|
+
return choose(*var['items']) do |menu|
|
37
|
+
menu.header = var['question']
|
38
|
+
if (var['default'])
|
39
|
+
menu.default = var['default']
|
40
|
+
menu.prompt = "(defaults to '#{menu.default}')"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def string(var)
|
46
|
+
return ask(var['question']) { |q| q.default = var['default'] }
|
47
|
+
end
|
48
|
+
|
49
|
+
def password(var)
|
50
|
+
return ask(var['question']) { |q| q.echo = false }
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Angerer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple command line prompt that generates configuration files by querying
|
14
|
+
the user for config values and creating a file based on a template
|
15
|
+
email: lord.of.war@gmx.ch
|
16
|
+
executables:
|
17
|
+
- confgen
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/confgen.rb
|
22
|
+
- bin/confgen
|
23
|
+
homepage: http://rubygems.org/gems/confgen
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.0.3
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Generate config files from user input
|
47
|
+
test_files: []
|