-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
|
||
// Required: Defines a description for the command that can be seen in command listings | ||
// and help dialogs | ||
'description': 'Give a greeting to the current user.', | ||
|
||
// The function that actually invokes the command. Simply pull the current state of the | ||
// "me" environment variable and print it to the console. | ||
'invoke': function(session, args, callback) { | ||
console.log('Hello, ' + session.env('me').bold); | ||
return callback(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var optimist = require('optimist'); | ||
|
||
module.exports = { | ||
|
||
// Required: Defines a description for the command that can be seen in command listings | ||
// and help dialogs | ||
'description': 'Tell the session who you are.', | ||
|
||
// Optional: Additional text to show how the command can be used. Can be multi-line, etc... | ||
'help': 'Usage: iam <name>', | ||
|
||
// The function that actually invokes the command. Optimist is being used here to parse | ||
// the array arguments that were provided to your command, however you can use whatever | ||
// utility you want | ||
'invoke': function(session, args, callback) { | ||
|
||
// Parse the arguments using optimist | ||
var argv = optimist.parse(args); | ||
|
||
// Update the environment to indicate who the specified user now is | ||
session.env('me', argv._[0] || 'unknown'); | ||
|
||
// The callback always needs to be invoked to finish the command | ||
return callback(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var colors = require('colors'); | ||
var path = require('path'); | ||
|
||
var Corporal = require('../../index'); | ||
var corporal = new Corporal({ | ||
|
||
// Commands will be loaded from JS files in the "commands" directory. Each command | ||
// exports an object that contains data and functions for describing and invoking | ||
// the command | ||
'commands': path.join(__dirname, 'commands'), | ||
|
||
// Define an initial environment: | ||
// * The arbitrary "me" environment variable defines who the "current user" is | ||
// * The ps1 variable pulls the current value of the "me" variable to put in the PS1 prompt | ||
// * The the "colors" module is used to provide "bold" styling on the PS1 | ||
// * The ps2 variable is used as the prompt prefix in multi-line commands. "> " is also | ||
// the default value | ||
'env': { | ||
'me': 'unknown', | ||
'ps1': '%(me)s$ '.bold, | ||
'ps2': '> ' | ||
} | ||
}); | ||
|
||
// Start the interactive prompt | ||
corporal.start(); |