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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public object Execute(IRepl repl, object[] args)
        {
            var response = string.Empty;
            var responseIsValid = false;

            while (!responseIsValid)
            {
                _console.Write("Are you sure you wish to exit? (y/n): ");
                response = (_console.ReadLine() ?? string.Empty).ToLowerInvariant();
                responseIsValid = response == "y" || response == "n";
            }

            if (response == "y")
            {
                repl.Terminate();
            }

            return null;
        }
Beispiel #4
0
        public object Execute(IRepl repl, object[] args)
        {
            var response        = string.Empty;
            var responseIsValid = false;

            while (!responseIsValid)
            {
                _console.Write("Are you sure you wish to exit? (y/n): ");
                response        = (_console.ReadLine() ?? string.Empty).ToLowerInvariant();
                responseIsValid = response == "y" || response == "n";
            }

            if (response == "y")
            {
                repl.Terminate();
            }

            return(null);
        }
Beispiel #5
0
        public object Execute(IRepl repl, object[] args)
        {
            if (repl == null)
            {
                throw new ArgumentNullException(nameof(repl));
            }

            var response        = string.Empty;
            var responseIsValid = false;

            while (!responseIsValid)
            {
                _console.WriteLine("Are you sure you wish to exit? (y/n):");
                response        = _console.ReadLine().ToLowerInvariant();
                responseIsValid = response == "y" || response == "n";
            }

            if (response == "y")
            {
                repl.Terminate();
            }

            return(null);
        }