From ea061d5b7aa3c41c32c4b3f6d79f389e176c1216 Mon Sep 17 00:00:00 2001 From: dianshi Date: Sat, 24 Jun 2023 08:40:22 +0100 Subject: Add all missing sources --- CmdLine/ClearScreen.swift | 8 +++++ CmdLine/CmdTool.swift | 62 ++++++++++++++++++++++++++++++++++++++ CmdLine/main.swift | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 CmdLine/ClearScreen.swift create mode 100644 CmdLine/CmdTool.swift create mode 100644 CmdLine/main.swift (limited to 'CmdLine') diff --git a/CmdLine/ClearScreen.swift b/CmdLine/ClearScreen.swift new file mode 100644 index 0000000..bcb15e2 --- /dev/null +++ b/CmdLine/ClearScreen.swift @@ -0,0 +1,8 @@ +// +// ClearScreen.swift +// CmdLine +// +// Created by Jacky Jack on 31/05/2023. +// + +import Foundation 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?) -> Void)? + //var helpDelegate:CmdTableHelp? + //var preconditionDelegate:CmdTablePrecondition? + //var autocompleteDelegate:CmdTableAutocomplete? + + init() { + command = "" + } +} + +public class CmdTable { + var table:Array = [] + + 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) { + let cmd0 = args[0] + var params0 = Array() + if args.count > 1 { + params0 = Array(args[1..!##UnsafeMutablePointer!#>, <#T##str: UnsafePointer!##UnsafePointer!#>, <#T##str_size: Int##Int#>) +//var p = cmd.Par() +var p = cmd.CmdParser() +//p.parse() +let r = p.parse("123 0x0 0b1 \"this is me\" asd123 a@1 1.20 admin@main.lv") +let r1 = p.parse("ls") +let r2 = p.parse("one") +let r3 = p.parse("ls 123") +let r4 = p.parse("args 0x0 0b1 \"this is me\" asd123 a@1 1.20 admin@main.lv") +for e in 0..?) { + print("List nothing") +} +cmd_ls.callback = call_ls + +let cmd_one = CmdTableEntry() +var cmd_one_i = 0 +cmd_one.command = "one" +func call_cmd(_ args:Array?) { + print("+1 == \(cmd_one_i)") + cmd_one_i += 1 +} +cmd_one.callback = call_cmd + +let cmd_show_args = CmdTableEntry() +func call_show_args(_ _args:Array?) { + if let args = _args { + for arg in args { + print("\(arg.val) ") + } + } +} +cmd_show_args.command = "args" +cmd_show_args.callback = call_show_args + +let commands = CmdTable() +commands.addEntry(cmd_ls) +commands.addEntry(cmd_one) +commands.addEntry(cmd_show_args) + + +commands.listCommands() + + +commands.execute(r) +commands.execute(r1) +commands.execute(r2) +commands.execute(r2) +commands.execute(r2) +commands.execute(r2) +commands.execute(r3) +commands.execute(r4) +print("Test CMD") + + -- cgit v1.2.3