After reading the proposal a second time, and reviewing parts of the implementation, I have some more suggestions for this proposal.
Command pattern/structure
In the "Alternatives Considered" section:
Support for Deleting Products/Targets/Dependencies and Renaming Products/Targets
This functionality was considered, but ultimately removed from the scope of the initial proposal. Most of these editing operations appear to be fairly uncommon, so it seems better to wait and see how the new commands are used in practice before rolling out more.
One common operation not covered by either the detailed design or the alternatives considered is adding new dependencies/targets to existing targets/products. I think it's fine if all additional commands are left for the future, but they should still be considered for the "scalability" of the proposed commands' pattern/structure.
The proposed commands use verb-noun for each operation:
swift package add-dependency <name> ...
swift package add-product <name> ...
swift package add-target <name> ...
If additional commands are to follow this pattern, they will probably be like:
swift package remove-dependency <name> ...
swift package remove-product <name> ...
swift package remove-target <name> ...
swift package rename-dependency <oldName> <newName> ...
swift package rename-product <oldName> <newName> ...
swift package rename-target <oldName> <newName> ...
swift package upgrade-dependency <name> ...
...
One concern I have here is that all the commands can get crowded at the swift package level, and it can make them more difficult to discover in documentation.
Mock output of the `--help` manual
$ swift package --help
OVERVIEW: Perform operations on Swift packages
USAGE: swift package [options] subcommand
OPTIONS:
... 21 existing options omitted ...
SUBCOMMANDS:
... 15 existing options omitted ...
add-dependency Add a dependency to the current package.
add-product Add a product to the current package.
add-target Add a target to the current package.
remove-dependency Remove a dependency from the current package.
remove-product Remove a product from the current package.
remove-target Remove a target from the current package.
rename-dependency Rename a dependency in the current package.
rename-product Rename a product in the current package.
rename-target Rename a target in the current package.
upgrade-dependency Upgrade a dependency in the current package.
...
SEE ALSO: swift build, swift run, swift test
I suggest changing the commands to the noun verb pattern, so all of them can be grouped under the dependency, product, and target subcommands:
swift package dependency add <name> ...
swift package dependency remove <name> ...
swift package dependency rename <oldName> <newName> ...
swift package dependency upgrade <name> ...
swift package product add <name> ...
swift package product remove <name> ...
swift package product rename <oldName> <newName> ...
swift package target add <name> ...
swift package target remove <name> ...
swift package target rename <oldName> <newName> ...
...
Mock output of the `--help` manuals
$ swift package --help
OVERVIEW: Perform operations on Swift packages
USAGE: swift package [options] subcommand
OPTIONS:
... 21 existing options omitted ...
SUBCOMMANDS:
... 15 existing options omitted ...
dependency Perform dependency-related operations on Swift packages.
product Perform product-related operations on Swift packages.
target Perform target-related operations on Swift packages.
SEE ALSO: swift build, swift run, swift test
$ swift package dependency --help
OVERVIEW: Perform dependency-related operations on Swift packages.
USAGE: swift package dependency subcommand
SUBCOMMANDS:
add Add a dependency to the current package.
remove Remove a dependency from the current package.
rename Rename a dependency in the current package.
upgrade Upgrade a dependency in the current package.
...
$ swift package target --help
OVERVIEW: Perform target-related operations on Swift packages.
USAGE: swift package target subcommand
SUBCOMMANDS:
add Add a target to the current package.
remove Remove a target from the current package.
rename Rename a target in the current package.
...
$ swift package product --help
OVERVIEW: Perform product-related operations on Swift packages.
USAGE: swift package product subcommand
SUBCOMMANDS:
add Add a product to the current package.
remove Remove a product from the current package.
rename Rename a product in the current package.
...
There are also precedents of this noun verb subcommand pattern in other programs. For example in Git:
git remote add myRemote https://path.to.my/remote
git remote remove origin
git remote rename oldName newName
git submodule add
git submodule status
git submodule init
URL and path
swift package add-target <name> [--type <type>] [--no-test-target] [--dependencies <dependencies>] [--url <url>] [--path <path>] [--checksum <checksum>][...]
- url/path : The URL for a remote binary target or path for a local one.
- checksum : The checksum for a remote binary target.
[...]
swift package add-dependency <dependency> [--exact <version>] [--revision <revision>] [--branch <branch>] [--from <version>] [--up-to-next-minor-from <version>]
- dependency : This may be the URL of a remote package, the path to a local package, or the name of a package in one of the user's package collections.
add-target uses separate --url and --path options, while add-dependency combines both into the dependency argument.
If SwiftPM is able to tell whether a dependency's path is local or remote, can one of the --url and --path options be dropped and have the remaining one take both local and remote paths?
From...to and from...through versions
Package.Dependency has these 2 static functions:
static func package(name: String? = nil, url: String, _ range: Range<Version>) -> Package.Dependency
Can this proposal add --to <version> and --through <version> to pair with --from <version>, so the add-dependency command can accept all supported version requirements?