Swiftpack.co - Package - vapor/console-kit


Stars: 210



Fix double-output of "Error: " label for command errors - 2020-06-30 09:41:59

This patch was authored and released by @gwynne.

Because CommandError.description includes the "Error: " label in the returned text, practically all formatted error output (especially such as found in vapor/toolbox) ends up printing Error: Error: ... for command errors. Since this table is redundant in the description of an Error anyway, we just remove it. The description of an Error is human-readable and therefore not parseable, and is thus not considered API, so this is considered a semver-patch change.

Error on unrecognized input - 2020-06-26 18:32:46

This patch was authored and released by @tanner0101.

Updates ConsoleKit to throw an error if unrecognized input is passed (#144).

ConsoleKit currently ignores any input it is unable to parse. This makes simple typos confusing to debug, for example:

$ vapor run serve --port=1337
Running on localhost:8080

In the above example, invalid option syntax is being used. However, ConsoleKit simply ignores it.

After this update, invalid syntax will result in an error:

$ vapor run serve --port=1337
Error: Input not recognized: --port=1337

Fix `Argument` Shell Completion - 2020-06-10 21:00:50

This patch was authored by @mliberman and released by @calebkleveter.

Fixes bash and zsh shell completion for Arguments.

Allow overriding whether ANSI escape sequences are output - 2020-03-30 23:32:59

This patch was authored and released by @gwynne.
  • Particularly useful for implementing a command-line option of the form --color=yes|no|auto (corresponding to setting the override to true, setting the override to false, and leaving it unset, respectively).
  • When not building in Xcode, an attempt is made to determine whether output is to a terminal that can support escape codes and they are suppressed if the answer is no.
  • Fixed some misaligned whitespace in --help's output.
  • An EOF on stdin (such as by pressing Ctrl-D) no longer causes Console.choose() and Console.confirm() to go into an infinite loop of printing the prompt over and over.

ConsoleKit 4.0.0 - 2020-03-27 22:08:42

Docs: https://docs.vapor.codes/4.0/logging/ https://docs.vapor.codes/4.0/commands/

More information on Vapor 4 official release: https://forums.swift.org/t/vapor-4-official-release-begins/34802

Release Candidate 1 - 2020-03-01 17:53:37

Updates to Swift 5.2 and macOS 10.15. Adds CI + README updates.

Release candidates represent the final shift toward focusing on bug fixes and documentation. Breaking changes will only be accepted for critical issues. We expect a final release of this package shortly after Swift 5.2's release date.

Remove extraneous quotes from logger metadata - 2020-02-26 23:38:30

Updates ConsoleLogger to remove unnecessary quotes from the logger metadata.


[ INFO ] GET /error ["request-id": "4B6C1861-FE36-494F-AFE3-0FF7DAAC9738"] (Vapor/Responder/DefaultResponder.swift:35)
[ ERROR ] TestError 500: This is a test. ["request-id": "4B6C1861-FE36-494F-AFE3-0FF7DAAC9738"] (Development/routes.swift:167)


[ INFO ] GET /error [request-id: 4B6C1861-FE36-494F-AFE3-0FF7DAAC9738] (Vapor/Responder/DefaultResponder.swift:35)
[ ERROR ] TestError 500: This is a test. [request-id: 4B6C1861-FE36-494F-AFE3-0FF7DAAC9738] (Development/routes.swift:167)

This patch was authored and released by @tanner0101.

Shell Completion Code Generation - 2020-02-26 21:21:30

Implements shell completion script generation for bash and zsh, and adds a flag to Commands to use it right out of the box:

// main.swift

// ...
var commands = Commands(enableAutocomplete: true)
// ...
let group = commands.group(help: "My command-line application")
try console.run(group, using: input)
// ...

The CommandGroup created will have an autocomplete command (a GenerateAutocompleteCommand) that can be used to generate shell completion scripts for the entire command hierarchy and its command-line arguments:

Usage: <executable> autocomplete [--shell,-s] [--output,-o] [--quiet,-q]

Generate shell completion scripts for the executable

   shell Generate a completion script for SHELL [ bash | zsh ].
         Defaults to the "SHELL" environment variable if possible.
  output Write the completion script to the file at OUTPUT, overwriting its contents.
         Defaults to printing to stdout.

   quiet Suppress any informational console output

Option and Argument signature values can optionally provide a CompletionAction. For example, in GenerateAutocompleteCommand.Signature:

    name: "shell", 
    // ...
    completion: .values(of: Shell.self)
var shell: Shell?

    name: "output",
    // ...
    completion: .files()
var output: String?

CompletionAction currently provides static factory methods for completing files (including directories), directories (excluding regular files), and a list of string values, as well as a convenience method for creating a list of values from a CaseIterable and LosslessStringConvertible type.

Make ConsoleText ExpressibleByStringInterpolation - 2020-01-23 21:13:44

Previously, to generate ConsoleText you had to append strings using + and consoleText().

let name = "Vapor"
console.output("Hello " + name.consoleText())

Now, ConsoleText supports string interpolation.

console.output("Hello \(name)")

String interpolation also allows you to pass an optional style parameter for adding colors.

console.output("Hello \(name, style: .info)")

ConsoleKit 4.0.0 Beta 2 - 2019-12-09 14:22:21

  • Removed CommandConfiguration struct (#124)

Commands struct gained the use(_:as:) method previously on CommandConfiguration.

  • Allow checking to see if an Optional is present in command call (#125)
  • Enabled test discovery on Linux (#127))

ConsoleKit 4.0.0 Beta 1 - 2019-10-24 18:55:04

  • CommandError is now an enum. (#122)
  • ConsoleLogger now stores the logging bootstrap's label during creation. (#123)

Notes: This change allows ConsoleLogger to print the label used for its creation when at .trace log level.

ConsoleKit v4.0.0-alpha.3 - 2019-10-16 22:34:56

Maybe You Meant 'Beta'?

No, this isn't supposed to be a beta release; but we do have suggestions! Command suggestions at that! If pass in a command that doesn't exist, ConsoleKit will automatically check to see if there are any commands with a similar name and suggest that maybe you meant one of them instead.

A big thanks to @tkrajacic for implementing this feature!

ConsoleKit 4.0.0 Alpha 2.1 - 2019-08-28 15:52:45

  • Added projectedValue to @Argument, @Option, and @Flag property wrappers. (#118)

Notes: This allows for the property wrapper backing for these signature arguments to be accessed from the command. To access, prefix the argument name with $.

ConsoleKit 4.0.0 Alpha 2 - 2019-08-27 22:19:07

  • Command signatures are now declared using property wrappers (#116, #115)

Here's an example command signature using the new API:

struct Cowsay: Command {
    struct Signature: CommandSignature {
        @Argument(name: "message", help: "What the cow should say") 
        var message: String

        @Option(name: "eyes", short: "e", help: "Change the cow's eyes")
        var eyes: String?

        @Option(name: "tongue", short: "t", help: "Change the cow's tongue")
        var tongue: String?

        @Flag(name: "borg", help: "uses == for cow's eyes")
        var borg: Bool

        init() { }

    let help = "Prints an ASCII cow with a message"

    func run(context: CommandContext, signature: Signature) throws {
        print(signature.message) // String
        print(signature.eyes) // String?
        print(signature.tongue) // String?
        print(signature.borg) // Bool
  • New type-erased protocols for Command and Group allow for dynamic commands to be implemented (#115, #113)
struct DynamicCommand: AnyCommand {
    var help: String = ""

    func run(using context: inout CommandContext) throws {
        XCTAssertEqual(context.input.arguments, ["true", "--count", "42"])

ConsoleKit 4.0.0 Alpha 1 - 2019-05-29 16:03:36

More information on Vapor 4 alpha releases:


API Docs:


Console 3.1.1 - 2019-03-22 13:22:34


  • Only extract a short flag if the raw flag string is -<short> (https://github.com/vapor/console/pull/94)

Console 3.1.0 - 2018-11-08 20:52:13


  • Created CustomActivity activity indicator type. this lets you easily create custom activity indicators with a series of characters that are looped over for the animation.
  • Added a customActivity method to the Console protocol, which initializes a new CustomActivity instance.
let indicator = context.console.customActivity(frames: ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"])
_ = try indicator.start(on: context.container)
// Do something that takes a long time.

Console 3.0.4 - 2018-11-06 14:35:45

Only logs command help when there are errors in command usage, no longer logs errors in the command execution.

Console 3.0.3 - 2018-10-30 21:32:20


  • Fixes an issue where ephemeral messages would not clear correctly. (#80)

Console 2.3.2 - 2018-05-30 01:29:03


  • Eliminate Swift 4.1 deprecation warnings.

Console 3.0.2 - 2018-05-02 20:30:53


  • -e short flag now supported for setting environment.

Console 3.0.1 - 2018-04-20 02:28:42


  • Console.output(...) now correctly defaults to printing a newline (#70).

Console 3.0.0 - 2018-04-05 20:05:53

💻 Console 3.0 (APIs for creating interactive CLI tools) is here!

Getting Started: https://docs.vapor.codes/3.0/console/getting-started/ https://docs.vapor.codes/3.0/command/getting-started/ https://docs.vapor.codes/3.0/logging/getting-started/

API Docs: https://api.vapor.codes/console/latest/Console https://api.vapor.codes/console/latest/Command https://api.vapor.codes/console/latest/Logging

Changes since final pre-release.


  • Added ConsoleText type for creating collections of differently styled strings. This makes it possible to output text with interpolated styles in one call to console.output(_:)
  • Cleaned up the loading and progress bars, now using an ActivityIndicator protocol.
  • Added lots of missing docblocks, made some APIs internal where possible to reduce API surface.

Milestone: 3.0.0

Console 3.0.0 RC 2.2 - 2018-03-27 15:29:14



  • Makes console.confirm non-throwing

API Docs: https://api.vapor.codes/console/3.0.0-rc.2.2/Command/

Milestone: 3.0.0-rc.2.2

Console 3.0.0 RC 2.1.1 - 2018-03-27 00:10:19


  • Adds support for -y, --yes and -n, --no flags for auto-answering console confirmations.

Console 3.0.0 RC 2.1 - 2018-03-25 04:06:16


  • Adds a commandLine settable computed property to Environment for parsing the environment's CLI arguments.

API Docs: https://api.vapor.codes/console/3.0.0-rc.2.1/Console/ https://api.vapor.codes/console/3.0.0-rc.2.1/Command/

Milestone: 3.0.0-rc.2.1

Console 3.0.0 RC 2.0.1 - 2018-03-22 00:41:56


  • Synchronizes printed log output to avoid garbled messages.

Console 3.0.0 RC 2 - 2018-03-21 20:28:23


  • Vapor is now running on Swift NIO!


  • Fixed an issue parsing short flags.


Console 3.0.0 RC 1 - 2018-02-23 04:09:53

Console 3.0.0 Beta 2 - 2018-02-22 01:11:17


  • Update to latest core package.
  • Update error structs.