Skip to content

Commit

Permalink
[api] Finished fleshing out forever columns * commands
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jul 11, 2011
1 parent 581a132 commit 091e949
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/forever
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ else if (action === 'columns') {
// and file then continue.
//
action = [action, file];
options = options.options[0];
options = options.options;
file = null;
}

Expand Down
14 changes: 11 additions & 3 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ forever.load = function (options) {
options.root = options.root || forever.root;
options.pidPath = options.pidPath || path.join(options.root, 'pids');
options.sockPath = options.sockPath || path.join(options.root, 'sock');
options.columns = options.columns || [
'uid', 'command', 'script', 'forever', 'pid', 'logfile', 'uptime'
];

//
// If forever is initalized and the config directories are identical
Expand All @@ -82,6 +79,17 @@ forever.load = function (options) {
//
try { forever.config.loadSync() }
catch (ex) { }

//
// Setup the columns for `forever list`.
//
options.columns = options.columns || forever.config.get('columns');
if (!options.columns) {
options.columns = [
'uid', 'command', 'script', 'forever', 'pid', 'logfile', 'uptime'
];
}


forever.config.set('root', options.root);
forever.config.set('pidPath', options.pidPath);
Expand Down
45 changes: 44 additions & 1 deletion lib/forever/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,50 @@ cli.clear = function (key) {
};

cli.columns = function (action, value) {
console.dir(arguments);
if (!~['add', 'rm', 'set'].indexOf(action)) {
forever.log.error('Invalid action: ' + ('columns ' + action).yellow);
forever.log.info('Use: ' + 'columns <add|rm|set>'.yellow);
return;
}

var columns = forever.config.get('columns'),
actions = { add: addColumn, rm: rmColumn, set: setColumns },
allColumns = Object.keys(forever.columns);

function addColumn () {
if (~columns.indexOf(value)) {
return forever.log.warn(value.magenta + ' already exists in forever');
}

forever.log.info('Adding column: ' + value.magenta);
columns.push(value);
}

function rmColumn () {
if (!~columns.indexOf(value)) {
return forever.log.warn(value.magenta + ' doesn\'t exist in forever');
}

forever.log.info('Removing column: ' + value.magenta);
columns.splice(columns.indexOf(value), 1);
}

function setColumns () {
forever.log.info('Setting columns: ' + value.join(' ').magenta);
columns = value;
}

if (action !== 'set') {
value = value[0];
}

if (!~allColumns.indexOf(value)) {
return forever.log.error('Unknown column: ' + value.magenta);
}

actions[action]();
forever.config.set('columns', columns);
forever.config.saveSync();
}

//
Expand Down

0 comments on commit 091e949

Please sign in to comment.