Skip to content

Commit d7a916b

Browse files
committed
feat: Adds default impl of the symbol of CommandRepresentable.
1 parent 73a2b3b commit d7a916b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Commander.xcodeproj/xcshareddata/xcschemes/commander-sample.xcscheme

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
</CommandLineArgument>
7878
<CommandLineArgument
7979
argument = "sample -h"
80+
isEnabled = "NO">
81+
</CommandLineArgument>
82+
<CommandLineArgument
83+
argument = "help"
8084
isEnabled = "YES">
8185
</CommandLineArgument>
8286
<CommandLineArgument

Sources/Commander/Commands/CommandRepresentable.swift

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public protocol CommandDispatchable: CommandDescribable {
122122
// MARK: - CommandDescribable.
123123

124124
extension CommandDispatchable {
125+
/// The command symbol also name of the command.
126+
public static var symbol: String {
127+
return String(reflecting: self).split(delimiter: ".").last?.camelcase2dashcase().replacingOccurrences(of: "-command", with: "") ?? ""
128+
}
125129
/// Returns the children of the insrance of `CommandDescribable`.
126130
public static var children: [CommandDescribable.Type] {
127131
return self.children as [CommandDispatchable.Type]

Sources/commander-sample/SampleCommand.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public struct SampleCommand: CommandRepresentable {
5050
}
5151
}
5252

53-
public static let children: [CommandDispatchable.Type] = [
53+
public static let children = [
5454
NoArgsCommand.self
5555
]
56-
public static let symbol: String = "sample"
56+
5757
public static let usage: String = "Show sample usage of commander"
5858

5959
public static func main(_ options: Options) throws {
@@ -70,7 +70,6 @@ public struct NoArgsCommand: CommandRepresentable {
7070
public init() { }
7171
}
7272

73-
@Option(usage: "set-args")
7473
public static var symbol: String = "set-args"
7574
public static let usage: String = "Set arguments of the command with given arguments"
7675

0 commit comments

Comments
 (0)