Skip to content

Commit

Permalink
Added better version output, and --about command.
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Aug 8, 2022
1 parent 4bd34f3 commit 63f783a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Sources/CommandShell/CommandEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ open class CommandEngine: CommandEngineProtocol {
open class var abstract: String {
return "<abstract goes here>"
}

open class var subcommands: [ParsableCommand.Type] {
return []
}
Expand All @@ -52,6 +53,28 @@ open class CommandEngine: CommandEngineProtocol {
return (info[.nameInfoKey] as? String) ?? CommandShell.executable
}

public var fullVersion: String {
var string = "Version \(version.asString)"
if let build = info[.buildInfoKey] {
string.append(" (\(build))")
}

return string
}

public var fullName: String {
return "\(name) \(fullVersion)"
}

public var about: String {
var string = fullName
if let copyright = info[.copyrightInfoKey] {
string.append("\n\(copyright)")
}

return string
}

func loadVersion() -> SemanticVersion {
if let string = (info[.versionInfoKey] as? String) {
return SemanticVersion(string)
Expand Down
7 changes: 5 additions & 2 deletions Sources/CommandShell/CommandShell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public struct CommandShell<Engine: CommandEngine>: ParsableCommand {
}

@Flag(help: "Show the version.") var version = false
@Flag(help: "Show some about information.") var about = false
@OptionGroup() var options: CommandShellOptions


Expand All @@ -32,8 +33,10 @@ public struct CommandShell<Engine: CommandEngine>: ParsableCommand {

public func run() throws {
let engine: Engine = options.loadEngine(info: commandShellExplicitInfo)
if version {
engine.output.log(engine.version.asString)
if about {
engine.output.log(engine.about)
} else if version {
engine.output.log(engine.fullVersion)
} else {
throw CleanExit.helpRequest(self)
}
Expand Down

0 comments on commit 63f783a

Please sign in to comment.