Beispiel #1
0
        //--- Class Methods ---
        public static void Main(string[] args)
        {
            var app = new CommandLineApplication {
                Name        = "AdventureBot.Cli",
                FullName    = "AdventureBot Command Line Interface",
                Description = "Choose-Your-Adventure CLI"
            };

            app.HelpOption();
            var filenameArg = app.Argument("<FILENAME>", "path to adventure file");

            app.OnExecute(() => {
                if (filenameArg.Value == null)
                {
                    Console.WriteLine(app.GetHelpText());
                    return;
                }
                if (!File.Exists(filenameArg.Value))
                {
                    app.ShowRootCommandFullNameAndVersion();
                    Console.WriteLine("ERROR: could not find file");
                    return;
                }

                // initialize the adventure from the adventure file
                Adventure adventure;
                try {
                    adventure = Adventure.LoadFrom(filenameArg.Value);
                } catch (AdventureException e) {
                    Console.WriteLine($"ERROR: {e.Message}");
                    return;
                } catch (Exception e) {
                    Console.WriteLine($"ERROR: unable to load file");
                    Console.WriteLine(e);
                    return;
                }

                // invoke adventure
                var state  = new AdventureState("cli", Adventure.StartPlaceId);
                var engine = new AdventureEngine(adventure, state);
                AdventureLoop(engine);
            });
            app.Execute(args);
        }