file_templater 0.1.1 → 0.1.2
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/lib/file_templater/options_handler.rb +28 -4
- data/lib/file_templater/variables.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbcda6006b6b3e49308db64982a9a48696d10e3
|
4
|
+
data.tar.gz: 97595b1474ce2db099e98ae523b7452d402b695a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e7450d71bdbf09dbe8479b6d0d06486de3698f12a53a51b74863e57a922e1adc89169b78d876d5cee3a01ecb5a2df40bb6a7ada79d4b264896ba3cba6be629
|
7
|
+
data.tar.gz: 51f8a7e76f0f57b45819bff36a04edd0f84a20aea037d814151bc2c5ebc00563bce13baaff7e5388740a2eff4aa13a73a8fffdf07f17c82a9a56ae9ffe4f9cc6
|
@@ -2,6 +2,9 @@ module FileTemplater
|
|
2
2
|
class OptionsHandler
|
3
3
|
def initialize(argv)
|
4
4
|
@nomodify = false
|
5
|
+
|
6
|
+
# Commands that can only be run once.
|
7
|
+
@template = nil
|
5
8
|
@binding = nil
|
6
9
|
|
7
10
|
@actions = []
|
@@ -15,12 +18,17 @@ module FileTemplater
|
|
15
18
|
o.on("-t", "--template TEMPLATE",
|
16
19
|
"Load TEMPLATE to insert",
|
17
20
|
"into the current directory") do |t|
|
18
|
-
@
|
21
|
+
can_only_be_used_once @template, "-t"
|
22
|
+
|
23
|
+
@actions << [:template]
|
24
|
+
@template = t
|
19
25
|
end
|
20
26
|
|
21
27
|
o.on("-b", "--binding BINDING",
|
22
28
|
"Load BINDING as the binding",
|
23
29
|
"for the loaded template") do |b|
|
30
|
+
can_only_be_used_once @binding, "-b"
|
31
|
+
|
24
32
|
@binding = b
|
25
33
|
end
|
26
34
|
|
@@ -47,8 +55,8 @@ module FileTemplater
|
|
47
55
|
@nomodify = true
|
48
56
|
end
|
49
57
|
|
50
|
-
o.on("-c", "--copy
|
51
|
-
"Copies
|
58
|
+
o.on("-c", "--copy THING", Array,
|
59
|
+
"Copies THING, a template or binding,",
|
52
60
|
"into current directory") do |tb|
|
53
61
|
@actions << [:copy, tb]
|
54
62
|
end
|
@@ -58,11 +66,16 @@ module FileTemplater
|
|
58
66
|
|
59
67
|
o.on_tail("-v", "--version", "Display the version") do
|
60
68
|
puts "File Templater (template) version " + VERSION
|
69
|
+
puts
|
70
|
+
puts "Copyright (C) 2015 Sam Craig"
|
71
|
+
puts "Licensed under the GNU General Public License version 3."
|
72
|
+
|
61
73
|
exit
|
62
74
|
end
|
63
75
|
|
64
76
|
o.on_tail("-h", "--help", "Show this message") do
|
65
77
|
puts o
|
78
|
+
|
66
79
|
exit
|
67
80
|
end
|
68
81
|
end
|
@@ -72,6 +85,9 @@ module FileTemplater
|
|
72
85
|
end
|
73
86
|
|
74
87
|
def process_actions
|
88
|
+
# All actions should be unique.
|
89
|
+
@actions.uniq!
|
90
|
+
|
75
91
|
@actions.each do |a|
|
76
92
|
command = a.first
|
77
93
|
arguments = a[1]
|
@@ -80,7 +96,7 @@ module FileTemplater
|
|
80
96
|
when :template
|
81
97
|
# arguments is the template name,
|
82
98
|
# @arguments are the extraneous arguments
|
83
|
-
template = Template.new(
|
99
|
+
template = Template.new(@template, @arguments, nomodify: @nomodify, bind: @binding)
|
84
100
|
template.load
|
85
101
|
when :add
|
86
102
|
arguments.each do |ar|
|
@@ -99,5 +115,13 @@ module FileTemplater
|
|
99
115
|
end
|
100
116
|
end
|
101
117
|
end
|
118
|
+
|
119
|
+
def can_only_be_used_once(variable, switch)
|
120
|
+
if variable
|
121
|
+
puts "The #{switch} switch can only be used once!"
|
122
|
+
|
123
|
+
exit
|
124
|
+
end
|
125
|
+
end
|
102
126
|
end
|
103
127
|
end
|