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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/confgen +6 -1
  3. data/lib/confgen.rb +39 -27
  4. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaef0c7a47a59addca740b704eb029d3512d3233
4
- data.tar.gz: 83997d440a237152b8dec7ee20fcc241810b0bde
3
+ metadata.gz: 9bd402bb6db29b410999e22408689a18124656a6
4
+ data.tar.gz: fa973f7774b7d6913a81468375604d7fb9434c40
5
5
  SHA512:
6
- metadata.gz: 8509affb9f3ddb99ee75db16952ec6706fa31fecd62ff74268bfcbe4accf5ca6573a48ab79535718fcb09c53197d5ee8c406c36a914c84677eaee296d9e46066
7
- data.tar.gz: 62d724b4debb8ceb8598d8766a1f859c5f87597be872ac892dbe4d33587762bc6707739b852f256548f08293bacd96bd74fbab70a2aed6016342b315fe041af6
6
+ metadata.gz: 88053fab2c5785a62ff85066426f455ec7d55f8fccfa7a473021fc35afdb52f9cf1258f2904306193b185673d2edc6e0ea8bba7b88c5a14c15f2c4452a6a6c60
7
+ data.tar.gz: 1d0f94ce01dda1d34a13d6b4c78306fb0d18bbdd4765afdf4cf9cd3001540b7c101941154a6569756b480d4344bb675497d7f2c4c969e38280571e766011c17b
@@ -2,5 +2,10 @@
2
2
 
3
3
  require("confgen")
4
4
 
5
+ sets = ARGV
6
+ if (sets.length === 0)
7
+ sets << "default"
8
+ end
9
+
5
10
  g = ConfGen.new(Dir.pwd)
6
- g.generate()
11
+ g.generate(sets)
@@ -1,37 +1,39 @@
1
1
 
2
- require("highline/import")
3
- require("yaml")
4
- require("erb")
5
- require("fileutils")
6
- require("pathname")
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
- template = config['template']
16
- destination = config['destination']
17
- data = gather(config)
18
-
19
- say("Generation will continue with the following data")
20
- say(data)
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
- File.open(dst.to_path(), 'w') do |f|
34
- f.write(tpl.result(b))
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(config)
57
+ def gather(configSet)
56
58
  data = Hash.new()
57
59
 
58
- config['variables'].each do |var|
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.3.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: []