Skip to content

Commit

Permalink
Add overwrite flag to create command (#5651)
Browse files Browse the repository at this point in the history
* Add overwrite flag to create command

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Sep 21, 2023
1 parent d56b355 commit 0ab84bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slick-pants-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": minor
---

feat:Add overwrite flag to create command
11 changes: 10 additions & 1 deletion gradio/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,22 @@ def _create(
str,
typer.Option(help="NPM install command to use. Default is 'npm install'."),
] = "npm install",
overwrite: Annotated[
bool,
typer.Option(help="Whether to overwrite the existing component if it exists.")
] = False
):
if not directory:
directory = pathlib.Path(name.lower())
if not package_name:
package_name = f"gradio_{name.lower()}"

directory.mkdir(exist_ok=True)
if directory.exists() and not overwrite:
raise ValueError(f"The directory {directory.resolve()} already exists. "
"Please set --overwrite flag or pass in the name "
"of a directory that does not already exist via the --directory option.")

directory.mkdir(exist_ok=overwrite)

if in_test_dir():
npm_install = "pnpm i --ignore-scripts"
Expand Down

0 comments on commit 0ab84bf

Please sign in to comment.