// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/** @typedef JsExecuteContext$$module$axiom$fs$js$execute_context */
var JsExecuteContext;

/**
 * Simple callback for a JsExecutable which echos the argument list to stdout
 * and exits.
 * @param {JsExecuteContext} cx
 */
export var main = function(cx) {
  cx.ready();
  var list = cx.getArg('_');
  var value;

  if (list.length == 1 && cx.getArg('pluck', true)) {
    value = list[0];
  } else {
    value = list;
  }

  cx.stdout.write(JSON.stringify(value, null, cx.getArg('space', '  ')) + '\n');
  return cx.closeOk();
};

export default main;

main.signature = {
  '_': '@',
  'pluck|p': '?',
  'space|s': '$'
};

@@ -695,16 +695,466 @@
 ntext;%0A%0A
+var help = %5B%0A  'Usage: echo %3Coptions%3E ...',%0A  '',%0A  'Options:',%0A  '',%0A  '  --no-p, --no-pluck',%0A  '      Always print the arguments as an array, even if there is only one.',%0A  '  -h, --help',%0A  '      Print this help message and exit.',%0A  '  -s, --space %3Cstring%3E',%0A  '      Specify the whitespace used in array and object literals.  Defaults',%0A  '      to %22  %22.',%0A  '',%0A  'Serializes the arguments using JSON.stringify and echos them to stdout.'%0A%5D;%0A%0A
 /**%0A * S
@@ -1324,16 +1324,130 @@
 eady();%0A
+%0A  if (cx.getArg('help', false)) %7B%0A    cx.stdout.write(help.join('%5Cr%5Cn') + '%5Cr%5Cn');%0A    return cx.closeOk();%0A  %7D%0A%0A
   var li
@@ -1739,16 +1739,16 @@
 ure = %7B%0A
-
   '_': '
@@ -1751,16 +1751,33 @@
 ': '@',%0A
+  'help%7Ch': '?',%0A
   'pluck

add help text to echo.