Hello folks,
I'm working on some improvements to the swift package init
templates and would love to hear what you think:
Here's a summary of the new usage:
OVERVIEW: Initialize a new package
USAGE: swift package init [--type <type>] [--name <name>]
OPTIONS:
--type <type> Package type: (default: library)
library - A package with a library.
executable - A package with an executable.
tool - A package with an executable that uses
Swift Argument Parser. Use this template
if you plan to have a rich set of command-line arguments.
empty - An empty package with a Package.swift manifest.
--name <name> Provide custom package name
--version Show the version.
-h, -help, --help Show help information.
You can check out the changes in the pull request for more details. A main goal of these changes is to simplify the template content for new packages without making too many assumptions about what the user is trying to make. For example, there was some usage of private(set)
which isn't a super common thing to show someone when they are getting started. So, the executable
template uses plain top-level code and the library
template just has a public function, both with a simple and friendly "Hello, world!".
Along with that, a couple of interesting enhancements:
-
Use links to documentation like the TSPL, Swift Argument Parser, and XCTest where appropriate to teach people more about writing Swift instead of template content. I think this is a lightweight and more timeless way to get people to fresh instructional content without making assumptions.
-
A new
tool
template will be available, which starts the user off with aParsableCommand
struct and adds a dependency on the latest stable version ofswift-argument-parser
. While theexecutable
template will continue to provide a bare executable, this template smooths the path for a more complete tool and promotes Swift's solution for managing command-line arguments.
After talking with @NeoNacho about this, it would be good to have a "latest" package requirement which allows a dependency to automatically take the latest stable version. For now, I can have swiftpm emit the latest appropriate version ofswift-argument-parser
explicitly into the generated manifest and adopt that later.
I would love to hear what you think about these changes. Thank you!