remotegcli-839862: Use 'exports' not 'canon'

We're using aliases for exports less and less.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Encapsulate the Canon

Previously there was a set of singleton stores of data, and some
exported functions (addCommand/removeCommand/etc) that manipulated them.
This made it impossible to have more than one set of commands which
made testing importing commands from one place to another hard. So this
change creates a Canon object to encapsulate those stores/functions.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Fixing command transplants

A few changes that fix the way we handle command proxying:
- getCommandSpecs now clones the commandSpecs object rather than
  exposing it to the outside
- Add an 'isParent' property to a commandSpec so the client side knows
  whether or not to generate an exec function
- Create a parent command for the set of imported commands

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Add unit tests

Also some minor tidy-ups for testCompletion.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Add prefix to requisition

With a prefix then we will first lookup what was typed with the given
prefix, before trying the unprefixed version.

The eventual goal is to make the following be equivalent (using git as
an example command)
>> git add -a
>> git commit -m blah
Or
>> context git
>> add -a
>> commit -m blah

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Hack to allow access to Requisition

We want users to stay away from Requisition, but the context command is
going to need to manipulate it, so we allow access to the Requisition
from a context in as nasty a way as possible to dissuade general use.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Add a 'context' command

This allows us to add a magic prefix to commands. See notes in previous
commit.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Refactor - unindent 'intro' command

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: convert() should always return a promise

converters.convert() was supposed to always return a promise, but if
there was no conversion to be done, then we just returned the original
object rather than a promise of it.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Factor out a 'serve' command

This commit does not need Mozilla review as it doesn't change files in
mozilla-central.

Extract a 'serve' command and a startup sequence which will help us
integrate socket.io better.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Create 'server start|stop' commands

This commit does not need Mozilla review as it doesn't change files in
mozilla-central.

Split the 'serve' command into 2: 'server start' and 'server stop'.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Add "--commands" option to "server start"

Allow remote command execution (turned off by default) using websockets
to asynchronously pass data between client and server.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Add "connect" command (to go with prev)

Add the client side counterpart to the "server start --commands"
addition in the previous commit.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Split help data and help formatting

Now we have converters working, we split out the formatting of help data
which also helps with remoting since the formatting can happen on the
client.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Split "pref list" data and formatting

Now we have converters working, we split out the formatting of pref data
which also helps with remoting since the formatting can happen on the
client.

Also use context.updateExec in place of context.exec because the
'command' way we're using it is deprecated.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Apply band-aid to "pref list"

It would be good to show this command some love, however it's undergone
some bit-rot, or maybe it was never loved properly. Anyway this comments
out the "Filter" and the edit buttons until we can make them work
properly.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Swap param order to typedData

The original order was wrong for 2 reasons:
* 'data' is more likely to be multi-line. 'type' never
* the ordering is hinted at in the name 'typedData'
The original thinking was that 'data' is more important than 'type' so
it should come first, but that doesn't feel like a strong enough case

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Split execution/conversion contexts

Previously there was a single 'context' object that essentially provided
a wrapper for a Requisition to allow us to evolve a Requisition and
hope to have a degree of backwards compatibility and safety. With
remoting and splitting execution from formatting there could be 2
different requisitions, so we split the execution functions from the
conversion functions.

To allow backwards compatibility we have a 'legacy' switch to make the
execution context act as it did previously.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Make "context" command use default document.

From the source:
"The ability to add functionality by adding a new script tag is specific
to a browser, so this code is not going to work in NodeJS/Firefox etc.
We export the document that we are using so multi-frame environments can
update the default document"

Signed-off-by: Joe Walker <jwalker@mozilla.com>
remotegcli-839862: Move createExecutionContext into Requisition

Now that we're caching the context objects, there is no need to have a
separate exported function to create them, so we make executionContext
and conversionContext property getters.

Signed-off-by: Joe Walker <jwalker@mozilla.com>