scriptcs/scriptcs — pull request #612 by filipw (2014-04-03 15:55:27+00:00)
Title: Replcommands

### Overview

This PR introduces the infrastructure for REPL commands. Fixes #224 and #237. The design is as discussed in #583.

The command is defined as follows:

public interface IReplCommand
{
string CommandName { get; }
object Execute(IScriptExecutor repl, object[] args);
}

And can either execute arbitrary code, or interact with the REPL (has access to `IScriptExecutor`). If it returns the value, it's printed to the REPL too. It should now enable easy extensiblity i.e. do something like requested in #402 or #427

The interesting thing is that you can also pass context variables to the REPL. For example:

> var x = 1;
> :myCommand hello x

Will pass `hello` string and `1` to command. This is done by evaluating the argument with the `ScriptEngine`- if it returns a value, use it, otherwise assume it's just a string.

### Commands included

Converted the existing REPL commands to this approach:

- `CwdCommand` (show working directory)
- `CdCommand` (change workign directory)
- `ClearCommand` (cls)
- `ResetCommand` (reset executor)

Also added `InstallCommand` - this fixes #609.
You can now do:

- `:install myPackage`
- `:install myPackage 0.3`
- `:install myPackagae 0.3 -pre`

### Extra points

- currently the infra loads all commands it can find in the `AppDomain`. The idea was that as long as you have a DLL with `IReplCommand`, it should be discovered. This is a bit too invasive, so we may want to change it for a better approach. At the moment it's not integrated with Modules, but it should be trivial to do.
- right now all of the commands are loaded with `:` - I think it's actually better to have a uniform way rather than have a couple of commands starting with `#` because Roslyn does that, and have the rest start with `:`. But of course it would be possible to have "system" commands that start with `#`.
- The code to parse command is now embedded into the `Repl` class. There are better ways to do it but I didn't want to do too much in one PR. See issue #434 - I think this should be tackled next.
- I have plenty of other examples if there is some interest in extending it further - some mentioned in #583 already - i.e. HttpCommand or Command to build other commands inline :-)

Let me know what you think!