Skip to content

Conversation

ReaNAiveD
Copy link
Member

@ReaNAiveD ReaNAiveD commented Sep 27, 2024

Description
The tree.json file is growing bigger and will cause problem for git command one day. So it is required to drop tree.json file in git repo and generate it only in local cache.

The PR dropping tree.json in aaz model: Azure/aaz#615

Backend

  • Add a new class CMDSpecsPartialCommandTree to support partial commands and command groups management.
  • Through overwriting the __getitem__ method of CMDSpecsCommandDict and CMDSpecsCommandGroupDict, support similar interface of PartialCommandTree and a full CommandTree.
  • Add new api /AAZ/Specs/CommandTree/Simple to get a simplified tree from folder structure.
  • Add new api /AAZ/Specs/CommandTree/Nodes/Leaves to batched get command leaves.

Frontend

  • Rewrite the CLIModGeneratorProfileCommandTree. Change it from class component to function component.
  • Support dynamic load of command tree leaves in ModGenerator.
  • Add new property selected to ProfileCTCommand and ProfileCTCommandGroup to mark selection state no matter it is loaded or not.
  • Change ProfileCommandTree to object instead of list.

# Conflicts:
#	src/web/src/views/cli/CLIModGeneratorProfileCommandTree.tsx
#	src/web/src/views/cli/CLIModGeneratorProfileTabs.tsx
#	src/web/src/views/cli/CLIModuleGenerator.tsx
@ReaNAiveD ReaNAiveD requested a review from kairu-ms September 27, 2024 09:22
@ReaNAiveD ReaNAiveD self-assigned this Sep 27, 2024
@ReaNAiveD ReaNAiveD marked this pull request as ready for review October 30, 2024 08:42
ReaNAiveD and others added 2 commits November 18, 2024 15:15
Comment on lines 572 to 606
def patch_partial_items(self, aaz_command_tree: CMDSpecsCommandTree):
aaz_command_tree = CMDSpecsPartialCommandTree(self.aaz_path, aaz_command_tree.root)
nodes = [self.root]
i = 0
while i < len(nodes):
command_group = nodes[i]
if isinstance(command_group, CMDSpecsCommandGroup):
if isinstance(command_group.command_groups, CMDSpecsCommandGroupDict):
for key in command_group.command_groups.keys():
raw_cg = command_group.command_groups.get_raw_item(key)
if isinstance(raw_cg, CMDSpecsCommandGroup):
nodes.append(raw_cg)
elif isinstance(raw_cg, CMDSpecsPartialCommandGroup):
command_group.command_groups[key] = aaz_command_tree.find_command_group(*raw_cg.names)
elif isinstance(command_group.command_groups, dict):
for cg in command_group.command_groups.values():
nodes.append(cg)
if isinstance(command_group.commands, CMDSpecsCommandDict):
for key in command_group.commands.keys():
raw_command = command_group.commands.get_raw_item(key)
if isinstance(raw_command, CMDSpecsPartialCommand):
command_group.commands[key] = aaz_command_tree.find_command(*raw_command.names)
i += 1

def patch(self):
tree_path = os.path.join(self.aaz_path, "Commands", "tree.json")
if not (os.path.exists(tree_path) and os.path.isfile(tree_path)):
return
try:
with open(tree_path, 'r', encoding="utf-8") as f:
data = json.load(f)
aaz_command_tree = CMDSpecsCommandTree(data)
self.patch_partial_items(aaz_command_tree)
except json.decoder.JSONDecodeError as e:
raise ValueError(f"Invalid Command Tree file: {tree_path}") from e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need those functions as we decided drop the tree.json directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Collaborator

@kairu-ms kairu-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM

@kairu-ms kairu-ms requested a review from necusjz December 5, 2024 08:50
@necusjz
Copy link
Member

necusjz commented Dec 6, 2024

i found there is a minor difference in the behavior of tmpl = get_templates()["command"] tmpl.render(command=node):
image

@ReaNAiveD
Copy link
Member Author

ReaNAiveD commented Dec 6, 2024

i found there is a minor difference in the behavior of tmpl = get_templates()["command"] tmpl.render(command=node): image

@necusjz The command.md is generated through a jinja2 template where \\\n is used to concat multi-line helps.
I would change the logic that extracts helps from markdown.

{%- if command.help.lines is not none and command.help.lines|length %}

{{ command.help.lines|join('\\\n')}}
{%- endif %}

@kairu-ms kairu-ms merged commit 4de9f14 into Azure:dev Dec 16, 2024
3 checks passed
@kairu-ms kairu-ms mentioned this pull request Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants