-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.js
85 lines (68 loc) · 1.51 KB
/
hello.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
// Import rtm-cli to use the utility functions
const rtm = require('rtm-cli');
/**
* Command Action
* This is the function that will be called
* @param {Array} args List of command arguments
* @param {Object} env Commander environment
*/
function action(args, env) {
// Get the name argument
let name = args[0];
// Get the friends list
let friends = args[1];
// Get the language code
let lang = env.lang !== undefined ? env.lang : 'en';
// Say Hello in the language
let greeting = '';
switch (lang) {
case 'en':
greeting = 'Hello';
break;
case 'es':
greeting = 'Hola';
break;
case 'fr':
greeting = 'Bonjour';
}
// Build the Greeting
greeting += ', ' + name;
if ( friends ) {
greeting += ' and ' + friends.join(' and ')
}
// Print the greeting
rtm.log(greeting);
// Use the finish utility function to exit the command
rtm.finish();
}
/**
* Define the command properties here
*/
module.exports = {
/**
* Command definition:
* command name and argument definition
*/
command: "hello <name> [friends...]",
/**
* Command options:
* add option flags to the command
*/
options: [
{
option: "-l, --lang <code>",
description: "language can be one of 'en', 'es' or 'fr'"
}
],
/**
* Command description:
* short helpful description of the command
*/
description: "Say Hello!",
/**
* Command action:
* the function called when executing the command
*/
action: action
};