ArgumentExtractor
A rudimentary helper for extracting options and flags from a string list representing command line arguments. The idea is to extract all known options and flags, leaving just the positional arguments. This does not handle well the case in which positional arguments (or option argument values) happen to have the same name as an option or a flag. It only handles the long --<name>
form of options, but it does respect --
as an indication that all remaining arguments are positional.
struct ArgumentExtractor
Citizens in PackagePlugin
Type members
init([String]
) Initializes a ArgumentExtractor with a list of strings from which to extract flags and options. If the list contains
--
, any arguments that follow it are considered to be literals.
Instance members
var remainingArguments: [String]
Returns all remaining arguments, including any literals after the first
--
if there is one.var unextractedOptionsOrFlags: [String]
Returns any unextracted flags or options (based strictly on whether remaining arguments have a “–” prefix).
func extractFlag(named: String
) -> Int Extracts flags of the form
--<name>
from the remaining arguments, and returns the count.func extractOption(named: String
) -> [String] Extracts options of the form
--<name> <value>
or--<name>=<value>
from the remaining arguments, and returns the extracted values.