Beispiel #1
0
    /// <summary>
    /// The main entry point.
    /// </summary>
    /// <param name="args">The command line arguments.</param>
    public static int Main(string[] args)
    {
        var path = default(string);

        for (var i = 0; i < args.Length; i++)
        {
            var arg = args[i];

            if (path == null)
            {
                if (arg.StartsWith("--"))
                {
                    switch (arg)
                    {
                    case "--debug":
                        Console.Clear();
                        Interpreter.Inspector = Inspect;
                        break;

                    case "--help":
                        PrintUsage();
                        return(0);

                    case "--test":
                        UnitTests.Run();
                        return(0);

                    default:
                        Console.WriteLine($"Invalid option: {arg}");
                        return(1);
                    }
                }
                else
                {
                    path = arg;
                }
            }
            else
            {
                Console.WriteLine($"Invalid argument: {arg}");
                return(1);
            }
        }

        if (path == null)
        {
            PrintUsage();
            return(1);
        }

        Console.CancelKeyPress += (s, e) => {
            if (Interpreter.Inspector != null)
            {
                running  = false;
                e.Cancel = true;
            }
        };

        try {
            Module.Load(path);
            return(0);
        } catch (ParseError error) {
            Console.WriteLine(error);
        } catch (Exception error) {
            Console.WriteLine($"ERROR: {error.Message}");

            if (error.GetStackTrace() is string stackTrace)
            {
                Console.WriteLine(stackTrace);
            }
        }

        return(1);
    }