예제 #1
0
        /// <inheritdoc />
        public IObservable <string> Execute(params string[] args)
        {
            return(Observable.Create <string>(o =>
            {
                var response = new StringBuilder();
                var grep = new ConsoleGrep(response);
                var commandLine = new Arguments(args);
                if (commandLine["h"] != null || commandLine["H"] != null)
                {
                    grep.PrintHelp();
                    o.OnNext(response.ToString());
                    o.OnCompleted();
                    return Disposable.Empty;
                }
                // The arguments /e and /f are mandatory
                if (commandLine["e"] != null)
                {
                    grep.RegEx = commandLine["e"];
                }
                else
                {
                    response.AppendLine("Error: No Regular Expression specified!");
                    response.AppendLine();
                    grep.PrintHelp();
                    o.OnNext(response.ToString());
                    o.OnCompleted();
                    return Disposable.Empty;
                }

                grep.IgnoreCase = (commandLine["i"] != null);
                grep.LineNumbers = (commandLine["n"] != null);
                grep.CountLines = (commandLine["c"] != null);

                // Do the search
                grep.Search(Messages.Take(Messages.Count - 1).ToList());

                o.OnNext(response.ToString());
                o.OnCompleted();
                return Disposable.Empty;
            }));
        }
예제 #2
0
        /// <inheritdoc />
        public IObservable<string> Execute(params string[] args)
        {
            return Observable.Create<string>(o =>
            {
                var response = new StringBuilder();
                var grep = new ConsoleGrep(response);
                var commandLine = new Arguments(args);
                if (commandLine["h"] != null || commandLine["H"] != null)
                {
                    grep.PrintHelp();
                    o.OnNext(response.ToString());
                    o.OnCompleted();
                    return Disposable.Empty;
                }
                // The arguments /e and /f are mandatory
                if (commandLine["e"] != null)
                    grep.RegEx = commandLine["e"];
                else
                {
                    response.AppendLine("Error: No Regular Expression specified!");
                    response.AppendLine();
                    grep.PrintHelp();
                    o.OnNext(response.ToString());
                    o.OnCompleted();
                    return Disposable.Empty;
                }

                grep.IgnoreCase = (commandLine["i"] != null);
                grep.LineNumbers = (commandLine["n"] != null);
                grep.CountLines = (commandLine["c"] != null);

                // Do the search
                grep.Search(Messages.Take(Messages.Count - 1).ToList());

                o.OnNext(response.ToString());
                o.OnCompleted();
                return Disposable.Empty;
            });
        }