let directory = operands[optional: 0]
let quiet = optionValues.have(quietOption)
let bare = optionValues.have(bareOption)
let templateDirectory = optionValues.findOptionalArgument(for: templateOption)
let gitDirectory = optionValues.findOptionalArgument(for: separateGitDirOption)
let shared = optionValues.findOptionalArgument(for: sharedOption)
Operand type. Define command accepts how many operands.
options
[Option]
Available options.
handler
CommandHandler
This block will be called with validated operands and option values. There are extensions for getting specific values from operand value array and option value array.
import Bouncer
let program = Program(commands: [initCommand])
let arguments = Array(CommandLine.arguments.dropFirst())
try? program.run(withArguments: arguments)
Case 1
Input
git-mock init .
Output
init command <https://git-scm.com/docs/git-init>
directory : .
quiet : false
bare : false
template dir : nil
git dir : nil
shared : nil
Bouncer
Command line argument parser. Bouncer does all the heavy lifting for you. Dive into business logic in no time.
Table of Contents
Synopsis
Parse
and grab values.
Installation
Add Bouncer to
Package.swift
.Now import!
Component
Option
Configuration for option like
--path
,-h
,--path ./temp
or-p./temp
. Check regular expressions for matching option inOptionNameRegex.swift
.name
String
[[:alnum:]\-]+
).shortName
Character?
optional
Bool
argumentType
OptionArgumentType
Operand
Basically, all of arguments following command are operands. Of course, except options and option arguments.
Command
Configuration for command.
name
[String]
["container", "start"]
.operandType
OperandType
options
[Option]
handler
CommandHandler
Program
Program is initialized with commands. Use program object to parse and run command.
Example
Init.swift
main.swift
Case 1
Input
Output
Case 2
Input
Output
Contribute
If you have good idea or suggestion? Please, don’t hesitate to open a pull request or send me an email.
Hope you enjoy building command line tool with Bouncer!