Ejemplo n.º 1
0
        public Action Parse(string[] args)
        {
            var parseResults = new FlagsParser().Parse(args);

            var flags = parseResults.Item2;

            args = parseResults.Item1;

            if (flags.ContainsKey("?"))
            {
                return(() => new UsageCommand(commands).Execute(args, flags));
            }

            if (args.Length > 0)
            {
                var arg = args[0];

                // is command?
                var command = commands.FirstOrDefault(x => x.IsTopLevel && x.Names.Any(y => y.IndexOf(arg) >= 0));
                if (command != null)
                {
                    return(() => command.Execute(args, flags));
                }

                // must be a task
                flags.Add("taskname", arg);
                return(() => new TaskCommand().Execute(args, flags));
            }
            else
            {
                flags.Add("taskname", "default");
                return(() => new TaskCommand().Execute(args, flags));
            }
        }
Ejemplo n.º 2
0
        public static Dictionary <string, IPapyrusFlag> GetFlags(this FlagsParser flagsParser)
        {
            var mappedDict = new Dictionary <string, IPapyrusFlag>();

            dynamic flagsDict = flagsParser.AsDynamic().DefinedFlags;

            foreach (var pair in flagsDict)
            {
                dynamic asDynamicPair = ReflectionMagic.PrivateReflectionUsingDynamicExtensions.AsDynamic(pair);
                mappedDict.Add(asDynamicPair.Key, new PapyrusFlag(asDynamicPair.Value));
            }

            return(mappedDict);
        }
Ejemplo n.º 3
0
        public FlagsFile(PapyrusProgram program, IScriptTextProvider textProvider, ILogger <FlagsFile> logger)
        {
            _program      = program;
            _textProvider = textProvider;

            _logger = logger;

            // TODO: Invalidate this
            _flagsFilePath = new CachedValue <string>(() => _program.GetFlagsFilePath().WaitForResult());

            _scriptText = new TokenEqualityCachedValue <ScriptText, string>(
                () => _textProvider.GetText(_flagsFilePath).WaitForResult(),
                (_) => _textProvider.GetTextVersion(_flagsFilePath).WaitForResult());

            _textProvider.OnScriptTextChanged += HandleScriptTextChanged;

            _parseResult = new TokenEqualityCachedValue <DiagnosticResult <dynamic>, string>(() =>
            {
                return(DiagnosticResult <dynamic> .TryWithDiagnostics((diagnostics) =>
                {
                    void errorHandler(object s, ErrorEventArgs e)
                    {
                        diagnostics.Add(e.ToDiagnostic());
                    }

                    var flagsLexer = new FlagsLexer(new CaseInsensitiveStringStream(_scriptText.Value.Text));
                    flagsLexer.OnError(errorHandler);

                    var flagsParser = new FlagsParser(new CommonTokenStream(flagsLexer));
                    flagsParser.OnError(errorHandler);

                    flagsParser.flags();

                    return flagsParser.AsDynamic().DefinedFlags;
                }));
            },
                                                                                             (_) => _scriptText.Value.Version);
        }
Ejemplo n.º 4
0
 public static void OnError(this FlagsParser parser, Action <object, ErrorEventArgs> handler)
 {
     OnError(parser, "ErrorHandler", handler);
 }