Skip to content

Commit

Permalink
added outfile
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Feb 12, 2024
1 parent f364f7e commit d6e5ad3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/codergpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
overwrite_option = click.option(
"--overwrite/--no-overwrite", is_flag=True, default=False, help="Overwrite the existing file."
)
output_option = click.option("-o", "--outfile", help="Output file to write to.")

coder = CoderGPT()

Expand Down Expand Up @@ -150,7 +151,8 @@ def optimize_code(path: Union[str, Path], function: str, classname: str, overwri
@path_argument
@function_option
@class_option
def write_test_code(path: Union[str, Path], function: str, classname: str):
@output_option
def write_test_code(path: Union[str, Path], function: str, classname: str, outfile: Union[str, Path] = None):
"""
Write tests for the code file.
Expand All @@ -164,14 +166,15 @@ def write_test_code(path: Union[str, Path], function: str, classname: str):

# Check if path is a file
if path.is_file():
coder.test_writer(path=path, function=function, classname=classname)
coder.test_writer(path=path, function=function, classname=classname, outfile=outfile)
else:
raise ValueError("The path provided is not a file.")


@main.command("document")
@path_argument
def write_documentation(path: Union[str, Path]):
@output_option
def write_documentation(path: Union[str, Path], outfile: Union[str, Path] = None):
"""
Write documentation files for the code file.
Expand All @@ -183,7 +186,7 @@ def write_documentation(path: Union[str, Path]):

# Check if path is a file
if path.is_file():
coder.documenter(path=path)
coder.documenter(path=path, outfile=outfile)
else:
raise ValueError("The path provided is not a file.")

Expand Down
1 change: 1 addition & 0 deletions src/codergpt/commenter/commenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def comment(self, code: str, filename: str, overwrite: bool = False, language: O
{
"input": f"Rewrite and return this {language} code with\
comments and sphinx docstrings in :param: format: \n{code}\n"
"Return just the code block since all this will be a file."
}
)

Expand Down
8 changes: 4 additions & 4 deletions src/codergpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ def optimizer(self, path: Union[str, Path], function: str = None, classname=None
# code, language = self.get_code(filename=path, function_name=function, class_name=classname)
code_optimizer.optimize(filename=path, function=function, classname=classname, overwrite=overwrite)

def test_writer(self, path: Union[str, Path], function: str = None, classname: str = None):
def test_writer(self, path: Union[str, Path], function: str = None, classname: str = None, outfile: str = None):
"""
Test the code file.
:param path: The path to the code file.
"""
code_tester = CodeTester(self.chain)
code_tester.write_tests(filename=path, function=function, classname=classname)
code_tester.write_tests(filename=path, function=function, classname=classname, outfile=outfile)

def documenter(self, path: Union[str, Path]):
def documenter(self, path: Union[str, Path], outfile: str = None):
"""
Document the code file.
:param path: The path to the code file.
"""
code_documenter = CodeDocumenter(self.chain)
code_documenter.document(filename=path)
code_documenter.document(filename=path, outfile=outfile)


if __name__ == "__main__":
Expand Down

0 comments on commit d6e5ad3

Please sign in to comment.