Skip to content

Commit

Permalink
Add load command.
Browse files Browse the repository at this point in the history
Use FileConceptNetwork to rewrite @save command, and to write @load command.
Use package.json to automatically give version.
  • Loading branch information
parmentf committed Aug 7, 2014
1 parent 615f37b commit 476e808
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/ector_command.js
Expand Up @@ -8,6 +8,7 @@
*/
"use strict";

var config = require('package');
var debug = require('debug')('ector:command');
var util = require('util');
var sugar = require('sugar');
Expand All @@ -17,7 +18,7 @@ var FileConceptNetwork = require('file-concept-network').FileConceptNetwork;
var Ector = require('ector');

program
.version('0.1.2')
.version(config.version)
.option('-p, --person [name]', 'set the name of the utterer', 'User')
.option('-b, --botname [botname]', 'set the name of the bot', 'ECTOR')
.option('-q, --quiet', 'shut up!')
Expand Down Expand Up @@ -73,11 +74,11 @@ var help = function (command) {
"- @person : change the utterer name (like -p)\n" +
"- @botname : change the bot's name (like -b)\n" +
"- @version : give the current version\n" +
"- @save : save Ector's Concept Network and state\n" +
"- @save : save Ector's Concept Network\n" +
"- @shownodes : show the nodes of the Concept Network\n" +
"- @showlinks : show the links of the Concept Network\n" +
"- @showstate : show the state of the nodes\n" +
// "- @load : load Ector's Concept Network and state\n" +
"- @load : load Ector's Concept Network\n" +
// "- @cleanstate: clean the state from the non-activated nodes\n" +
// "- @log [file]: log the entries in the file (no file turns off the logging)\n" +
// "- @status : show the status of Ector (Concept Network, states)\n" +
Expand Down Expand Up @@ -155,22 +156,19 @@ var treatPhrase = function (phrase) {
console.error('Error while saving to file cn.json!\n%s', err);
}
});
var cnsJson = new Buffer(JSON.stringify(ector.cns[ector.username].nodeState));
var fileName = ector.username.parameterize();
var fCNS = fs.open(fileName + '_state.json', 'w', function (err, fd) {
if (!err) {
fs.write(fd, cnsJson, 0, cnsJson.length, 0, function (err) {
if (err) {
console.error(err);
}
});
}
else if (phrase === '@load') {
debug('@load');
ector.cn.load('cn.json', function (err) {
debug(' end of cn.load', err);
if (err) {
console.error('Error while loading from file cn.json!\n%s', err);
}
});
}
else if (phrase.startsWith('@')) {
console.log('This command does not exist.');
}
// TODO: wrote @load
// When it is not a command (beginning with @)
else {
var nodes = ector.addEntry(phrase);
Expand Down

0 comments on commit 476e808

Please sign in to comment.