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

Add --output option to conan new command #17359

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions conan/cli/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def new(conan_api, parser, *args):
parser.add_argument("-d", "--define", action="append",
help="Define a template argument as key=value, e.g., -d name=mypkg")
parser.add_argument("-f", "--force", action='store_true', help="Overwrite file if it already exists")
parser.add_argument("-of", "--output-folder", help="Output folder for the generated files",
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
default=os.getcwd())

args = parser.parse_args(*args)
# Manually parsing the remainder
Expand Down Expand Up @@ -59,18 +61,18 @@ def new(conan_api, parser, *args):

# Saving the resulting files
output = ConanOutput()
cwd = os.getcwd()
output_folder = args.output_folder
# Making sure they don't overwrite existing files
for f, v in sorted(template_files.items()):
path = os.path.join(cwd, f)
path = os.path.join(output_folder, f)
if os.path.exists(path) and not args.force:
raise ConanException(f"File '{f}' already exists, and --force not defined, aborting")
save(path, v)
output.success("File saved: %s" % f)

# copy non-templates
for f, v in sorted(non_template_files.items()):
path = os.path.join(cwd, f)
path = os.path.join(output_folder, f)
if os.path.exists(path) and not args.force:
raise ConanException(f"File '{f}' already exists, and --force not defined, aborting")
shutil.copy2(v, path)
Expand Down