From 0267f03fac61fb2a780903838c730e1b431e7941 Mon Sep 17 00:00:00 2001 From: Grant Gurvis Date: Wed, 29 May 2024 12:43:24 -0700 Subject: [PATCH] Checkout repo --- .github/workflows/build.yml | 1 + src/aws_cli_plugin/__init__.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56239b4..460eaca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,7 @@ jobs: build-completion: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - name: Setup Rye run: curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash - run: echo "$HOME/.rye/shims" >> $GITHUB_PATH diff --git a/src/aws_cli_plugin/__init__.py b/src/aws_cli_plugin/__init__.py index 0b5369d..71f0369 100644 --- a/src/aws_cli_plugin/__init__.py +++ b/src/aws_cli_plugin/__init__.py @@ -1,11 +1,11 @@ import json import re import os -from os.path import dirname, realpath +from pathlib import Path from awscli.customizations.commands import BasicCommand from awscli.clidriver import ServiceCommand, ServiceOperation -exportDirectory = dirname(dirname(dirname(realpath(__file__)))) +exportDirectory = Path("export") exportTypescript = True @@ -174,14 +174,14 @@ def saveJsonAsSpec(d, path): else "var completionSpec =" ) extension = ".ts" if exportTypescript else ".js" - directory = "{}/export/{}/".format( - exportDirectory, "ts" if exportTypescript else "js" + + file_path = exportDirectory.joinpath("ts" if exportTypescript else "js").joinpath( + f"{path}{extension}" ) - final = "{} {}".format(prefix, json.dumps(d, indent=4)) + file_path.parent.mkdir(parents=True, exist_ok=True) - f = open(directory + path + extension, "w") - f.write(final) - f.close() + final = f"{prefix} {json.dumps(d, indent=4)}" + file_path.write_text(final) root = {"name": "aws", "subcommands": []} @@ -200,7 +200,7 @@ def read_commands(command_table, session, **kwargs): print("ServiceCommand:", command_name) spec = generateCompletionSpecSkeleton(command_name, command) - path = "aws/{}".format(spec["name"]) + path = f"aws/{spec["name"]}" saveJsonAsSpec(spec, path) root["subcommands"].append( @@ -215,7 +215,7 @@ def read_commands(command_table, session, **kwargs): print("ServiceOperation:", command._parent_name, command_name) elif isinstance(command, BasicCommand): spec = parseBasicCommand(command) - path = "aws/{}".format(spec["name"]) + path = f"aws/{spec["name"]}" # save spec file to disk saveJsonAsSpec(spec, path)