-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow creation of non-existent directory during swift package init
#8401
Allow creation of non-existent directory during swift package init
#8401
Conversation
Running `swift package init --package-path <dir-does-not-exists>` results in an error when SPM attempts to change directories in to the directory that doesn't exist. Add a new boolean to the `_SwiftCommand` protocol that lets commands opt in to creating the directory at `--package-path` if it doesn't exist. Opt in `InitCommand` to this behaviour. Issue: swiftlang#8393
swift package init
swift package init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though I would not close #8393 as one of the expected behaviours is not currently implemented.
swift package init --package-path <dir>
should:
- create the directory, and populate the package if it does not exists
- should populate the package if the directory exists and is empty
- prompt the user for action if the directory exists and is non-empty
- should error if
<dir>
exists as a file
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really welcome addition to the init package workflow.
@swift-ci test |
@swift-ci test linux |
Running
swift package init --package-path <dir-does-not-exists>
results in an error when SwiftPM attempts to change directories in to the directory that doesn't exist.Motivation:
It is rare that a user wants to do a
swift package init
in a folder that already has content. A typical pattern is tomkdir mypackage && cd my package && swift package init
. SwiftPM already has a--package-path
flag indicating the package folder that the command should operate on, but attempting to use this to create a folder that doesn't exist duringswift package init
results in an error when SwiftPM attempts to chdir to the --package-path that doesn't exist.Modifications:
Add a new boolean to the
_SwiftCommand
protocol that lets commands opt in to creating the directory at--package-path
if it doesn't exist. Opt inInitCommand
to this behaviour.Result:
swift package init --package-path ./mypackage
successfully initializes a package in./mypackage
, even if./mypackage
doesn't exist.Issue: #8393