I wasn’t sure if I should include this article as part of this series. But for the sake of completion, I decided to include it. This article is very short, but it tells us how to actually install our own tool in a system so we can start using it without writing its full path.
To recap, and before I end my series in Swift’s ArgumentParser, let’s give a quick overview of everything we have learned so far:
In the past four weeks we have explored many of the features available to us via ArgumentParser and how to use them. Here’s a recap of everything we learned so far:
In this article, we will not explore a feature exposed to us via ArgumentParser. Instead, we will learn how to do something very essential: Creating tools that require asynchronous APIs.
Writing Command Line Tools in Swift Using ArgumentParser, Part 4: Customizing Help
In the past few weeks, we have explored how to use ArgumentParser and many of its features. It’s great that ArgumentParser provides a lot of functionality for free, but it wouldn’t make sense to build great tools that users can’t figure out how to use. This week is all about that.
We saw how ArgumentParser can build a lot of documentation for free, but we can actually do more. This week, we will explore how we can improve the documentation generated for our command line tools.
Last week we explored how we can build a simple command line tool. We learned how to use @Argument, @Option, and @Flag as the building blocks for ArgumentParser command line tools. We we saw last week was enough to build many simple tools, but there’s still a lot to explore, and cool things to learn.
This week we will learn about input validation and errors, so we can build better tools that take more constrained parameters when relevant.
A few weeks ago, the Swift project introduced the ArgumentParser package. This package makes it easy to write command line tools by providing automatic parsing, documentation generation, and more.
In this article, we will explore ArgumentParser, and how we can start building some command line tools with it, using the basic building blocks, which are three Property Wrappers called Argument, Option, and Flag.
Project Configuration
Open Xcode and create a new project of type “Command Line Tool”. You cannot use this project type for iOS/iPadOS, so if you don’t find it, head over to the Mac tab.