private bool ExecuteLine(IRepl repl)
        {
            var prompt = string.IsNullOrWhiteSpace(repl.Buffer) ? "> " : "* ";

            try
            {
                var line = _console.ReadLine(prompt);

                if (line == null)
                {
                    return(false);
                }

                if (!string.IsNullOrWhiteSpace(line))
                {
                    repl.Execute(line);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c to exit)" + Environment.NewLine);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            _repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            try
            {
                if (!string.IsNullOrWhiteSpace(_scriptName))
                {
                    _logger.Info(string.Format("Loading script: {0}", _scriptName));
                    _repl.Execute(string.Format("#load {0}", _scriptName));
                }

                while (ExecuteLine(_repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(CommandResult.Error);
            }

            _repl.Terminate();
            return(CommandResult.Success);
        }
        public object Execute(IRepl repl, object[] args)
        {
            if (repl == null || args == null || args.Length == 0)
            {
                return null;
            }

            var gistId = args[0].ToString();
            var files = _Downloader.DownloadGistFiles(gistId);

            foreach (var script in files.Select(File.ReadAllText))
            {
                repl.Execute(script, null);
            }

            return null;
        }
Beispiel #4
0
        public CommandResult Execute()
        {
            _fileSystemMigrator.Migrate();

            _console.WriteLine("scriptcs (ctrl-c to exit or :help for help)" + Environment.NewLine);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            _composer.Compose(workingDirectory);

            _repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            if (!string.IsNullOrWhiteSpace(_scriptName))
            {
                _logger.InfoFormat("Executing script '{0}'", _scriptName);
                try
                {
                    _repl.Execute(string.Format("#load {0}", _scriptName));
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error executing script '{0}'", ex, _scriptName);
                    return(CommandResult.Error);
                }
            }

            try
            {
                while (ExecuteLine(_repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error executing REPL", ex);
                return(CommandResult.Error);
            }

            _repl.Terminate();
            return(CommandResult.Success);
        }
        private static bool ExecuteLine(IRepl repl)
        {
            Console.Write(string.IsNullOrWhiteSpace(repl.Buffer) ? "> " : "* ");

            try
            {
                var line = Console.ReadLine();

                if (!string.IsNullOrWhiteSpace(line))
                {
                    repl.Execute(line);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
Beispiel #6
0
        private bool ExecuteLine(IRepl repl)
        {
            _console.Write(string.IsNullOrWhiteSpace(repl.Buffer) ? "> " : "* ");

            try
            {
                var line = _console.ReadLine();

                if (!string.IsNullOrWhiteSpace(line))
                {
                    repl.Execute(line);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool ExecuteLine(IRepl repl)
        {
            var prompt = string.IsNullOrWhiteSpace (repl.Buffer) ? "> " : "* ";

            try
            {
                var line = _console.ReadLine(prompt);

                if (line == null)
                    return false;

                if (!string.IsNullOrWhiteSpace(line))
                {
                    repl.Execute(line);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }