diff options
Diffstat (limited to '')
-rw-r--r-- | ConsoleApp/Main.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/ConsoleApp/Main.cs b/ConsoleApp/Main.cs new file mode 100644 index 0000000..322d277 --- /dev/null +++ b/ConsoleApp/Main.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; + +namespace ConsoleApp { + class MainClass { + private static Dictionary<string, Command> CommandLookup; + + private static void SetupCommands() { + CommandLookup = new Dictionary<string, Command>(); + + CommandLookup.Add("init", new InitCommand()); + CommandLookup.Add("list", new ListCommand()); + CommandLookup.Add("import-obj", new ImportObjCommand()); + CommandLookup.Add("export-obj", new ExportObjCommand()); + CommandLookup.Add("export-collada", new ExportColladaCommand()); + CommandLookup.Add("export-textures", new ExportTexturesCommand()); + } + + public static void Main(string[] args) { + Console.WriteLine("NW4RTools by Treeki"); + Console.WriteLine(); + + SetupCommands(); + + // process the command line + string cmd; + string[] cmdArgs; + + if (args.Length == 0) { + cmd = "help"; + cmdArgs = new string[0]; + } else { + cmd = args[0]; + cmdArgs = new string[args.Length - 1]; + + for (int i = 1; i < args.Length; i++) { + cmdArgs[i - 1] = args[i]; + } + } + + // handle Help if needed + if (cmd == "help") { + Help(cmdArgs); + return; + } + + // otherwise, pass it on + if (CommandLookup.ContainsKey(cmd)) { + CommandLookup[cmd].Execute(cmdArgs); + } else { + Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", cmd); + } + } + + private static void Help(string[] args) { + if (args.Length == 0) { + Console.WriteLine("Available commands:"); + + foreach (var cmd in CommandLookup) { + Console.WriteLine("- {0}: {1}", cmd.Key, cmd.Value.Description); + } + + Console.WriteLine(); + Console.WriteLine("For additional info, try: help <command-name>"); + + } else { + if (CommandLookup.ContainsKey(args[0])) { + Console.WriteLine("Help for {0}:", args[0]); + string[] helpArgs = new string[args.Length - 1]; + + for (int i = 1; i < args.Length; i++) { + helpArgs[i - 1] = args[i]; + } + + Console.WriteLine(CommandLookup[args[0]].GetHelp(helpArgs)); + + } else { + Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", args[0]); + } + } + } + } +} + |