sfn-parameters 0.2.0 → 0.2.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/CHANGELOG.md +3 -0
- data/lib/sfn-parameters/command.rb +116 -73
- data/lib/sfn-parameters/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a5dff19c967089f79139776c3e592a178614fb79
|
|
4
|
+
data.tar.gz: 0ba68820d8c71adc5cc6ab9fad5afaadd4e820b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44869723132b17dda13a221830edda6d355efa95930f5ff54b24a78d0a2b851798b84bf47214af65862442533f341ba92885d887e00074af5b645c0f4c08002f
|
|
7
|
+
data.tar.gz: 4a1b69b524e8f040acb78365746d4c137ff36b4871608ea1654a1ed6a6873879d7b6fe50ef808ad1fa41cecb34cd3df3862760c481b28318418c7dc280417f43
|
data/CHANGELOG.md
CHANGED
|
@@ -8,87 +8,127 @@ module Sfn
|
|
|
8
8
|
include SfnParameters::Utils
|
|
9
9
|
include Sfn::CommandModule::Base
|
|
10
10
|
|
|
11
|
+
# Default contents for new item creation
|
|
12
|
+
NEW_ITEM_DEFAULT = Smash.new(
|
|
13
|
+
:parameters => {},
|
|
14
|
+
:compile_parameters => {},
|
|
15
|
+
:apply_stacks => [],
|
|
16
|
+
:stacks => {}
|
|
17
|
+
)
|
|
18
|
+
|
|
11
19
|
# Execute parameters action request
|
|
12
20
|
def execute!
|
|
13
|
-
action, item = arguments[0,
|
|
21
|
+
action, item = arguments[0].to_s, arguments[1].to_s
|
|
14
22
|
ui.info "Running parameters action #{ui.color(action.to_s, :bold)}"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if(content[:sfn_parameters_lock])
|
|
21
|
-
ui.puts ui.color('no-op', :yellow)
|
|
22
|
-
ui.warn "Item is already locked! (#{item})"
|
|
23
|
-
else
|
|
24
|
-
thing = lock_content(content)
|
|
25
|
-
val = format_json(thing)
|
|
26
|
-
File.write(item, val)
|
|
27
|
-
ui.puts ui.color('locked', :blue)
|
|
28
|
-
end
|
|
29
|
-
when :unlock
|
|
30
|
-
item = validate_item(item)
|
|
31
|
-
ui.print " Unlocking #{ui.color(item, :bold)}... "
|
|
32
|
-
content = load_json(File.read(item)).to_smash
|
|
33
|
-
if(content[:sfn_parameters_lock])
|
|
34
|
-
content = unlock_content(content)
|
|
35
|
-
content.delete(:sfn_lock_enabled)
|
|
36
|
-
File.write(item, format_json(content))
|
|
37
|
-
ui.puts ui.color('unlocked', :green)
|
|
38
|
-
else
|
|
39
|
-
ui.puts ui.color('no-op', :yellow)
|
|
40
|
-
ui.warn "Item is already unlocked! (#{item})"
|
|
23
|
+
if(respond_to?("run_action_#{action}"))
|
|
24
|
+
send("run_action_#{action}", item)
|
|
25
|
+
else
|
|
26
|
+
allowed_actions = public_methods.grep(/^run_action/).sort.map do |item|
|
|
27
|
+
item.to_s.sub('run_action_', '')
|
|
41
28
|
end
|
|
42
|
-
|
|
29
|
+
raise ArgumentError.new "Unsupported action received `#{action}`. " \
|
|
30
|
+
"Allowed: #{allowed_actions.join(', ')}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Perform locking on item
|
|
35
|
+
#
|
|
36
|
+
# @param item [String] item to lock
|
|
37
|
+
def run_action_lock(item)
|
|
38
|
+
item = validate_item(item)
|
|
39
|
+
ui.print " Locking #{ui.color(item, :bold)}... "
|
|
40
|
+
content = load_json(File.read(item)).to_smash
|
|
41
|
+
if(content[:sfn_parameters_lock])
|
|
42
|
+
ui.puts ui.color('no-op', :yellow)
|
|
43
|
+
ui.warn "Item is already locked! (#{item})"
|
|
44
|
+
else
|
|
45
|
+
thing = lock_content(content)
|
|
46
|
+
val = format_json(thing)
|
|
47
|
+
File.write(item, val)
|
|
48
|
+
ui.puts ui.color('locked', :blue)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Perform unlocking on item
|
|
53
|
+
#
|
|
54
|
+
# @param item [String] item to lock
|
|
55
|
+
def run_action_unlock(item)
|
|
56
|
+
item = validate_item(item)
|
|
57
|
+
ui.print " Unlocking #{ui.color(item, :bold)}... "
|
|
58
|
+
content = load_json(File.read(item)).to_smash
|
|
59
|
+
if(content[:sfn_parameters_lock])
|
|
60
|
+
content = unlock_content(content)
|
|
61
|
+
content.delete(:sfn_lock_enabled)
|
|
62
|
+
File.write(item, format_json(content))
|
|
63
|
+
ui.puts ui.color('unlocked', :green)
|
|
64
|
+
else
|
|
65
|
+
ui.puts ui.color('no-op', :yellow)
|
|
66
|
+
ui.warn "Item is already unlocked! (#{item})"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Perform show on item
|
|
71
|
+
#
|
|
72
|
+
# @param item [String] item to lock
|
|
73
|
+
def run_action_show(item)
|
|
74
|
+
item = validate_item(item)
|
|
75
|
+
content = load_json(File.read(item)).to_smash
|
|
76
|
+
if(content[:sfn_parameters_lock])
|
|
77
|
+
ui.print ui.color(' *', :bold)
|
|
78
|
+
ui.print " Unlocking #{ui.color(item, :bold)} for display... "
|
|
79
|
+
content = unlock_content(content)
|
|
80
|
+
content.delete(:sfn_lock_enabled)
|
|
81
|
+
ui.puts ui.color('unlocked', :green)
|
|
82
|
+
end
|
|
83
|
+
ui.puts format_json(content)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Perform create on item
|
|
87
|
+
#
|
|
88
|
+
# @param item [String] item to lock
|
|
89
|
+
def run_action_create(item)
|
|
90
|
+
unless(ENV['EDITOR'])
|
|
91
|
+
raise ArgumentError.new '$EDITOR must be set for create/edit commands!'
|
|
92
|
+
end
|
|
93
|
+
begin
|
|
43
94
|
item = validate_item(item)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
ui.puts format_json(content)
|
|
53
|
-
when :create, :edit
|
|
54
|
-
unless(ENV['EDITOR'])
|
|
55
|
-
raise ArgumentError.new '$EDITOR must be set for create/edit commands!'
|
|
56
|
-
end
|
|
57
|
-
begin
|
|
58
|
-
item = validate_item(item)
|
|
59
|
-
rescue ArgumentError
|
|
60
|
-
new_item = true
|
|
61
|
-
item = new_item(item)
|
|
62
|
-
end
|
|
63
|
-
FileUtils.mkdir_p(File.dirname(item))
|
|
64
|
-
tmp = Bogo::EphemeralFile.new('sfn-parameters')
|
|
65
|
-
content = new_item ? Smash.new : load_json(File.read(item)).to_smash
|
|
66
|
-
if(content[:sfn_parameters_lock])
|
|
67
|
-
ui.print ui.color(' *', :bold)
|
|
68
|
-
ui.print " Unlocking #{ui.color(item, :bold)} for edit... "
|
|
69
|
-
content = unlock_content(content)
|
|
70
|
-
ui.puts ui.color('unlocked', :green)
|
|
71
|
-
end
|
|
72
|
-
lock_enabled = content.delete(:sfn_lock_enabled) || new_item
|
|
73
|
-
tmp.write(format_json(content))
|
|
74
|
-
tmp.flush
|
|
75
|
-
system("#{ENV['EDITOR']} #{tmp.path}")
|
|
76
|
-
tmp.rewind
|
|
77
|
-
content = load_json(tmp.read).to_smash
|
|
95
|
+
rescue ArgumentError
|
|
96
|
+
new_item = true
|
|
97
|
+
item = new_item(item)
|
|
98
|
+
end
|
|
99
|
+
FileUtils.mkdir_p(File.dirname(item))
|
|
100
|
+
tmp = Bogo::EphemeralFile.new('sfn-parameters')
|
|
101
|
+
content = new_item ? NEW_ITEM_DEFAULT : load_json(File.read(item)).to_smash
|
|
102
|
+
if(content[:sfn_parameters_lock])
|
|
78
103
|
ui.print ui.color(' *', :bold)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
ui.print " Unlocking #{ui.color(item, :bold)} for edit... "
|
|
105
|
+
content = unlock_content(content)
|
|
106
|
+
ui.puts ui.color('unlocked', :green)
|
|
107
|
+
end
|
|
108
|
+
lock_enabled = content.delete(:sfn_lock_enabled) || new_item
|
|
109
|
+
tmp.write(format_json(content))
|
|
110
|
+
tmp.flush
|
|
111
|
+
system("#{ENV['EDITOR']} #{tmp.path}")
|
|
112
|
+
tmp.rewind
|
|
113
|
+
content = load_json(tmp.read).to_smash
|
|
114
|
+
ui.print ui.color(' *', :bold)
|
|
115
|
+
if(lock_enabled)
|
|
116
|
+
ui.print " Locking #{ui.color(item, :bold)} for storage... "
|
|
117
|
+
content = lock_content(content)
|
|
118
|
+
ui.puts ui.color('locked', :blue)
|
|
88
119
|
else
|
|
89
|
-
|
|
90
|
-
"Allowed: lock, unlock, show, create, edit"
|
|
120
|
+
ui.puts " Storing #{ui.color(item, :bold)} for storage... #{ui.color('unlocked', :yellow)}"
|
|
91
121
|
end
|
|
122
|
+
File.write(item, format_json(content))
|
|
123
|
+
tmp.close
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Perform edit on item
|
|
127
|
+
#
|
|
128
|
+
# @param item [String] item to lock
|
|
129
|
+
def run_action_edit(item)
|
|
130
|
+
validate_item(item)
|
|
131
|
+
run_action_create(item)
|
|
92
132
|
end
|
|
93
133
|
|
|
94
134
|
# Expand path for new item if required
|
|
@@ -122,6 +162,9 @@ module Sfn
|
|
|
122
162
|
# @param item [String]
|
|
123
163
|
# @return [String]
|
|
124
164
|
def validate_item(item)
|
|
165
|
+
if(item.to_s.empty?)
|
|
166
|
+
raise NameError.new 'Item name is required. No item name provided.'
|
|
167
|
+
end
|
|
125
168
|
items = [
|
|
126
169
|
item,
|
|
127
170
|
File.join(
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sfn-parameters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Roberts
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sfn
|