diff options
Diffstat (limited to 'CmdLine/CmdTool.swift')
-rw-r--r-- | CmdLine/CmdTool.swift | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/CmdLine/CmdTool.swift b/CmdLine/CmdTool.swift new file mode 100644 index 0000000..41d35d8 --- /dev/null +++ b/CmdLine/CmdTool.swift @@ -0,0 +1,62 @@ +// +// CmdTool.swift +// CmdLine +// +// Created by Jacky Jack on 13/06/2023. +// + +import Foundation +import cmd + + +public class CmdTool { + init() { + + } +} + + + +public class CmdTableEntry { + var command:String + var callback:((Array<cmd.CmdToken>?) -> Void)? + //var helpDelegate:CmdTableHelp? + //var preconditionDelegate:CmdTablePrecondition? + //var autocompleteDelegate:CmdTableAutocomplete? + + init() { + command = "" + } +} + +public class CmdTable { + var table:Array<CmdTableEntry> = [] + + init() { + + } + + func addEntry(_ cmd: CmdTableEntry) { + table.append(cmd) + } + + func listCommands() { + for command in table { + print("CMD: \(command.command) callback:\(command.callback)") + } + } + + func execute(_ args: Array<CmdToken>) { + let cmd0 = args[0] + var params0 = Array<CmdToken>() + if args.count > 1 { + params0 = Array<CmdToken>(args[1..<args.count]) + } + for cmd in self.table { + if cmd.command == cmd0.val { + print("Found command executing ...") + cmd.callback!(params0) + } + } + } +} |