using System; using System.Collections.Generic; namespace ConsoleApp { class MainClass { private static Dictionary CommandLookup; private static void SetupCommands() { CommandLookup = new Dictionary(); 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 "); } 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]); } } } } }