Commits

Anonymous committed 058476f

Configuration loading and updating done

Comments (0)

Files changed (2)

lib/commands/config-set.js

+var config = require('../config');
+
 exports.desc = 'Set bbdev configuration parameter';
 
 exports.run = function(opts, callback) {
         args = args[0].split('=');
     }
 
-    console.log(args);
+    // load the config, apply the changed setting and then save the config
+    config.load(function(cfg) {
+        cfg[args[0]] = args[1] || '';
+
+        // save the configuration
+        config.save(cfg, callback);
+    });
 };
-var path = require('path'),
+var fs = require('fs'),
+    path = require('path'),
     _ = require('underscore'),
     homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'],
-    configFile = path.resolve(homePath, '.bbdev'),
+    configFile = path.resolve(homePath, '.worx'),
 
     defaultConfig = {
         deviceIp: '169.254.0.1'
         // apply defaults to the config and trigger the callback
         callback(_.defaults(config, defaultConfig));
     });
+};
+
+exports.save = function(data, callback) {
+    var output;
+
+    // update the configuration
+    _.extend(config, data);
+
+    // stringify the data in a sensible format
+    output = JSON.stringify(config, null, '  ');
+
+    // save the file
+    fs.writeFile(configFile, output, 'utf8', callback);
 };