A small command router chooses the work to run from a command string.

Route a command

command_router.swift
let command = 
let message: String

switch command {
case "build":
    message = "building app"
case "test":
    message = "running tests"
case "deploy":
    message = "deploying site"
default:
    message = "unknown command"
}

print(message)
let command = 
let message: String

switch command {
case "build":
    message = "building app"
case "test":
    message = "running tests"
case "deploy":
    message = "deploying site"
default:
    message = "unknown command"
}

print(message)
let command = 
let message: String

switch command {
case "build":
    message = "building app"
case "test":
    message = "running tests"
case "deploy":
    message = "deploying site"
default:
    message = "unknown command"
}

print(message)
command router Many command-line tools start by reading a command name and selecting the matching action.