confgen 0.3.0 → 0.4.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 +4 -4
- data/bin/confgen +6 -1
- data/lib/confgen.rb +39 -27
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd402bb6db29b410999e22408689a18124656a6
|
4
|
+
data.tar.gz: fa973f7774b7d6913a81468375604d7fb9434c40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88053fab2c5785a62ff85066426f455ec7d55f8fccfa7a473021fc35afdb52f9cf1258f2904306193b185673d2edc6e0ea8bba7b88c5a14c15f2c4452a6a6c60
|
7
|
+
data.tar.gz: 1d0f94ce01dda1d34a13d6b4c78306fb0d18bbdd4765afdf4cf9cd3001540b7c101941154a6569756b480d4344bb675497d7f2c4c969e38280571e766011c17b
|
data/bin/confgen
CHANGED
data/lib/confgen.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
|
2
|
-
require(
|
3
|
-
require(
|
4
|
-
require(
|
5
|
-
require(
|
6
|
-
require(
|
2
|
+
require('highline/import')
|
3
|
+
require('yaml')
|
4
|
+
require('erb')
|
5
|
+
require('fileutils')
|
6
|
+
require('pathname')
|
7
|
+
require('pp')
|
7
8
|
|
8
9
|
class ConfGen
|
9
10
|
def initialize(path)
|
10
11
|
@path = path
|
11
12
|
end
|
12
13
|
|
13
|
-
def generate()
|
14
|
+
def generate(sets)
|
14
15
|
config = locate()
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if (agree("Continue [y/n]?", true))
|
23
|
-
b = binding
|
24
|
-
config["templates"].each() do |template|
|
25
|
-
src = Pathname.new(ERB.new(@confPath.join(template["src"]).to_path()).result(b))
|
26
|
-
dst = Pathname.new(ERB.new(@confPath.join(template["dst"]).to_path()).result(b))
|
27
|
-
tpl = ERB.new(File.read(src.to_path()))
|
28
|
-
|
29
|
-
if (!dst.dirname.directory?)
|
30
|
-
FileUtils.mkdir_p(dst.dirname.to_path())
|
31
|
-
end
|
16
|
+
sets.each() do |setName|
|
17
|
+
configSet = config[setName]
|
18
|
+
data = gather(configSet)
|
19
|
+
|
20
|
+
say('Generation will continue with the following data')
|
21
|
+
print(configSet, data)
|
32
22
|
|
33
|
-
|
34
|
-
|
23
|
+
if (agree('Continue [y/n]?', true))
|
24
|
+
b = binding
|
25
|
+
configSet['templates'].each() do |template|
|
26
|
+
src = Pathname.new(ERB.new(@confPath.join(template['src']).to_path()).result(b))
|
27
|
+
dst = Pathname.new(ERB.new(@confPath.join(template['dst']).to_path()).result(b))
|
28
|
+
tpl = ERB.new(File.read(src.to_path()))
|
29
|
+
|
30
|
+
if (!dst.dirname.directory?)
|
31
|
+
FileUtils.mkdir_p(dst.dirname.to_path())
|
32
|
+
end
|
33
|
+
|
34
|
+
File.open(dst.to_path(), 'w') do |f|
|
35
|
+
f.write(tpl.result(b))
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -52,16 +54,26 @@ class ConfGen
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
def gather(
|
57
|
+
def gather(configSet)
|
56
58
|
data = Hash.new()
|
57
59
|
|
58
|
-
|
60
|
+
configSet['variables'].each do |var|
|
59
61
|
data[var['name']] = self.send(var['type'], var)
|
60
62
|
end
|
61
63
|
|
62
64
|
return data
|
63
65
|
end
|
64
66
|
|
67
|
+
def print(configSet, data)
|
68
|
+
configSet['variables'].each do |var|
|
69
|
+
if (var['type'] == 'password')
|
70
|
+
say(" #{var['name']}: ****")
|
71
|
+
else
|
72
|
+
say(" #{var['name']}: #{data[var['name']]}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
65
77
|
def choice(var)
|
66
78
|
return choose(*var['items']) do |menu|
|
67
79
|
menu.header = var['question']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Angerer
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-04-04 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: highline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
13
27
|
description: Simple command line prompt that generates configuration files by querying
|
14
28
|
the user for config values and creating a file based on a template
|
15
29
|
email: lord.of.war@gmx.ch
|
@@ -32,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
46
|
requirements:
|
33
47
|
- - '>='
|
34
48
|
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
49
|
+
version: '2.0'
|
36
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - '>='
|
@@ -43,5 +57,5 @@ rubyforge_project:
|
|
43
57
|
rubygems_version: 2.0.3
|
44
58
|
signing_key:
|
45
59
|
specification_version: 4
|
46
|
-
summary: Generate config files from user input
|
60
|
+
summary: Generate config files from user input on the command line
|
47
61
|
test_files: []
|