Skip to content

Commit

Permalink
Allowed reloading commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancelotbronner committed Mar 8, 2020
1 parent 566feeb commit 57f2a42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions Sources/TerminalCommands/Interpreter/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class Interpreter {
public static func load(commands: Command...) { load(commands: commands) }

public static func help() {
print()
for group in groups {
group.displayHelp()
print()
Expand Down
36 changes: 21 additions & 15 deletions Sources/TerminalCommands/States/State Machine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,7 @@ public final class StateMachine {
return stack[stack.count - 2]
}

//MARK: - Methods

public static func run(starting with: State) {
push(with)
while true {
Interpreter.prompt()
}
}

public static func run(starting with: State, while go: @autoclosure () -> Bool) {
push(with)
while go() {
Interpreter.prompt()
}
}
//MARK: Accessors

public static func push(_ s: State) {
stack.append(s)
Expand Down Expand Up @@ -80,6 +66,26 @@ public final class StateMachine {
push(s)
}

//MARK: - Methods

public static func run(starting with: State) {
push(with)
while true {
Interpreter.prompt()
}
}

public static func run(starting with: State, while go: @autoclosure () -> Bool) {
push(with)
while go() {
Interpreter.prompt()
}
}

public static func reloadCommands() {
Interpreter.load(commands: current.controls)
}

//MARK: - Utilities

private static func remove() {
Expand Down

0 comments on commit 57f2a42

Please sign in to comment.