diff --git a/src/rougail/output_json/__init__.py b/src/rougail/output_json/__init__.py index 1de0258..d31a8ed 100644 --- a/src/rougail/output_json/__init__.py +++ b/src/rougail/output_json/__init__.py @@ -126,49 +126,58 @@ class RougailOutputJson: def parse_family( self, - conf, - child, + parent, + parent_obj, namespace, ): - for option in conf: - if option.isoptiondescription(): - if option.isleadership(): - parent = [] + for child in parent: + if child.isoptiondescription(): + if child.isleadership(): + child_obj = [] self.parse_sequence( - option, - parent, + child, + child_obj, ) else: if ( namespace is None and self.support_namespace - and option.group_type() is groups.namespace + and child.group_type() is groups.namespace ): - subnamespace = option.name() + subnamespace = child.name() else: subnamespace = namespace - parent = {} - self.parse_family(option, parent, subnamespace) - child[option.name()] = parent + child_obj = self.get_default_family(child) + self.parse_family(child, child_obj, subnamespace) + self.family_informations(parent, parent_obj, child, child_obj) else: - child[option.name()] = option.value.get() + self.variable_informations(parent_obj, child) def parse_sequence( self, - conf, - parent, + child, + obj, ): - leader, *followers = list(conf) + leader, *followers = list(child) leader_values = leader.value.get() for idx, leader_value in enumerate(leader_values): leader_dict = {leader.name(): leader_value} - parent.append(leader_dict) + obj.append(leader_dict) for follower in list(followers): if follower.index() != idx: continue followers.remove(follower) leader_dict[follower.name()] = follower.value.get() + def get_default_family(self, child): + return dict() + + def family_informations(self, parent, parent_obj, child, child_obj): + parent_obj[child.name()] = child_obj + + def variable_informations(self, parent_obj, child): + parent_obj[child.name()] = child.value.get() + RougailOutput = RougailOutputJson diff --git a/tests/results/test/00_7help.json b/tests/results/test/00_7help.json index 1a797c5..6242dc5 100644 --- a/tests/results/test/00_7help.json +++ b/tests/results/test/00_7help.json @@ -1,4 +1,5 @@ { "var1": "string1", - "var2": "string1" + "var2": "string1", + "var3": "string1" } \ No newline at end of file diff --git a/tests/results/test/20_7help_family.json b/tests/results/test/20_7help_family.json index 7a15905..e826103 100644 --- a/tests/results/test/20_7help_family.json +++ b/tests/results/test/20_7help_family.json @@ -4,5 +4,8 @@ }, "family2": { "var": "string1" + }, + "family3": { + "var": "string1" } } \ No newline at end of file diff --git a/tests/results/test_namespace/00_7help.json b/tests/results/test_namespace/00_7help.json index bbe108c..f6b6d41 100644 --- a/tests/results/test_namespace/00_7help.json +++ b/tests/results/test_namespace/00_7help.json @@ -1,6 +1,7 @@ { "rougail": { "var1": "string1", - "var2": "string1" + "var2": "string1", + "var3": "string1" } } \ No newline at end of file diff --git a/tests/results/test_namespace/20_7help_family.json b/tests/results/test_namespace/20_7help_family.json index f789944..e855ba0 100644 --- a/tests/results/test_namespace/20_7help_family.json +++ b/tests/results/test_namespace/20_7help_family.json @@ -5,6 +5,9 @@ }, "family2": { "var": "string1" + }, + "family3": { + "var": "string1" } } } \ No newline at end of file diff --git a/tests/results/test_namespace_read_write/00_7help.json b/tests/results/test_namespace_read_write/00_7help.json index 174ee51..d126aae 100644 --- a/tests/results/test_namespace_read_write/00_7help.json +++ b/tests/results/test_namespace_read_write/00_7help.json @@ -1,6 +1,7 @@ { "rougail": { "var1": null, - "var2": null + "var2": null, + "var3": null } } \ No newline at end of file diff --git a/tests/results/test_namespace_read_write/20_7help_family.json b/tests/results/test_namespace_read_write/20_7help_family.json index 23b18b3..26af43c 100644 --- a/tests/results/test_namespace_read_write/20_7help_family.json +++ b/tests/results/test_namespace_read_write/20_7help_family.json @@ -5,6 +5,9 @@ }, "family2": { "var": null + }, + "family3": { + "var": null } } } \ No newline at end of file diff --git a/tests/results/test_read_write/00_7help.json b/tests/results/test_read_write/00_7help.json index be7160d..52a98ea 100644 --- a/tests/results/test_read_write/00_7help.json +++ b/tests/results/test_read_write/00_7help.json @@ -1,4 +1,5 @@ { "var1": null, - "var2": null + "var2": null, + "var3": null } \ No newline at end of file diff --git a/tests/results/test_read_write/20_7help_family.json b/tests/results/test_read_write/20_7help_family.json index a6c6baa..8f0329a 100644 --- a/tests/results/test_read_write/20_7help_family.json +++ b/tests/results/test_read_write/20_7help_family.json @@ -4,5 +4,8 @@ }, "family2": { "var": null + }, + "family3": { + "var": null } } \ No newline at end of file