Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /*
2 * Copyright 2012, Mozilla Foundation and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
17 'use strict';
19 var host = require('../util/host');
20 var l10n = require('../util/l10n');
21 var cli = require('../cli');
23 exports.items = [
24 {
25 // 'cd' command
26 item: 'command',
27 name: 'cd',
28 description: l10n.lookup('cdDesc'),
29 manual: l10n.lookup('cdManual'),
30 params: [
31 {
32 name: 'directory',
33 type: {
34 name: 'file',
35 filetype: 'directory',
36 existing: 'yes'
37 },
38 description: l10n.lookup('cdDirectoryDesc')
39 }
40 ],
41 returnType: 'string',
42 exec: function(args, context) {
43 context.shell.cwd = args.directory;
44 return l10n.lookupFormat('cdOutput', [ context.shell.cwd ]);
45 }
46 },
47 {
48 // 'exec' command
49 item: 'command',
50 name: 'exec',
51 description: l10n.lookup('execDesc'),
52 manual: l10n.lookup('execManual'),
53 params: [
54 {
55 name: 'command',
56 type: 'string',
57 description: l10n.lookup('execCommandDesc')
58 }
59 ],
60 returnType: 'output',
61 exec: function(args, context) {
62 var cmdArgs = cli.tokenize(args.command).map(function(arg) {
63 return arg.text;
64 });
65 var cmd = cmdArgs.shift();
67 var execSpec = {
68 cmd: cmd,
69 args: cmdArgs,
70 env: context.shell.env,
71 cwd: context.shell.cwd
72 };
74 return host.exec(execSpec).then(function(output) {
75 if (output.code === 0) {
76 return output;
77 }
79 throw output.data;
80 }, function(output) {
81 throw output.data;
82 });
83 }
84 },
85 {
86 // How we display the output of a generic exec command: we have to assume
87 // that it is a string to be displayed in a monospaced font
88 item: 'converter',
89 from: 'output',
90 to: 'view',
91 exec: function(output, context) {
92 return {
93 html: '<pre>${output.data}</pre>',
94 data: { output: output }
95 };
96 }
97 },
98 {
99 item: 'converter',
100 from: 'output',
101 to: 'string',
102 exec: function(output, context) {
103 return output.data;
104 }
105 }
106 ];