Skip to content

Commit 2efb8cd

Browse files
committed
- Fix parents revalidation issue
1 parent 1805a1e commit 2efb8cd

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/bashly/script/command.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def option_keys
1717
end
1818
end
1919

20+
attr_accessor :parent_command
21+
attr_writer :parents
22+
2023
# Returns the name to be used as an action.
2124
# - If it is the root command, the action is "root"
2225
# - Else, it is all the parents, except the first one (root) joined
@@ -100,9 +103,10 @@ def command_names
100103
def commands
101104
return [] unless options["commands"]
102105
options["commands"].map do |options|
103-
options['parents'] = parents + [name]
104-
options['parent_command'] = self
105-
Command.new options
106+
result = Command.new options
107+
result.parents = parents + [name]
108+
result.parent_command = self
109+
result
106110
end
107111
end
108112

@@ -182,15 +186,10 @@ def group_string
182186
end
183187
end
184188

185-
# Returns the Command instance of the direct parent
186-
def parent_command
187-
options['parent_command']
188-
end
189-
190189
# Returns an array of all parents. For example, the command
191190
# "docker container run" will have [docker, container] as its parents
192191
def parents
193-
options['parents'] || []
192+
@parents ||= []
194193
end
195194

196195
# Returns only commands that are not private

spec/bashly/script/command_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
describe Script::Command do
44
let(:fixture) { :basic_command }
55
fixtures = load_fixture('script/commands')
6-
subject { described_class.new fixtures[fixture] }
6+
subject do
7+
result = described_class.new fixtures[fixture]
8+
result.parents = result.options['parents']
9+
result
10+
end
711

812
describe '#action_name' do
913
context "when it is the root command" do

0 commit comments

Comments
 (0)