The flags from the previous recipe are a type of command-line argument. This chapter will expand on other uses for these arguments by constructing a command that supports nested subcommands. This will demonstrate flagsets and also use positional arguments that are passed into your application.
Like the previous recipe, this one requires a main function to run. There are a number of third-party packages that deal with complex nested arguments and flags, but we'll investigate how to do this using only the standard library.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter2/cmdargs.
- Navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter2...