Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add skip option in init commands #3179

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.22.1 Jul 4, 2024

### Enhancements:
- Add a `-s`/`--skip-if-exists` option to the `init` command to avoid reinitializing a repo if one already exists (stevenjlm)

## 3.22.0 Jun 20, 2024

### Enhancements:
Expand Down
12 changes: 10 additions & 2 deletions aim/cli/init/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
dir_okay=True,
writable=True))
@click.option('-y', '--yes', is_flag=True, help='Automatically confirm prompt')
def init(repo, yes):
@click.option('-s', '--skip-if-exists', is_flag=True, help='Skip initialization if the repo already exists')
def init(repo, yes, skip_if_exists):
"""
Initializes new repository in the --repo directory.
Initializes new repository in the current working directory if --repo argument is not provided:
Expand All @@ -20,8 +21,15 @@ def init(repo, yes):
repo_path = clean_repo_path(repo) or os.getcwd()
re_init = False
if Repo.exists(repo_path):
if yes:
if yes and skip_if_exists:
raise click.BadParameter('Conflicting init options.'
'Either specify -y/--yes or -s/--skip-if-exists')
elif yes:
re_init = True
elif skip_if_exists:
click.echo(
'Repo exists at {}. Skipped initialization.'.format(repo.root_path))
return
else:
re_init = click.confirm('Aim repository is already initialized. '
'Do you want to re-initialize to empty Aim repository?')
Expand Down
Loading