2016-10-09 15:14:02 -04:00
"use strict" ;
2014-08-24 20:19:03 -04:00
var ClientManager = new require ( "../clientManager" ) ;
var program = require ( "commander" ) ;
var child = require ( "child_process" ) ;
2016-12-15 01:13:43 -05:00
var colors = require ( "colors/safe" ) ;
2014-09-13 08:23:17 -04:00
var Helper = require ( "../helper" ) ;
2017-08-21 01:49:32 -04:00
const Utils = require ( "./utils" ) ;
2014-08-26 14:00:12 -04:00
2014-08-24 20:19:03 -04:00
program
. command ( "edit <name>" )
2016-12-15 01:13:43 -05:00
. description ( ` Edit user file located at ${ colors . green ( Helper . getUserConfigPath ( "<name>" ) ) } . ` )
2017-08-21 01:49:32 -04:00
. on ( "--help" , Utils . extraHelp )
2014-08-24 20:19:03 -04:00
. action ( function ( name ) {
var users = new ClientManager ( ) . getUsers ( ) ;
if ( users . indexOf ( name ) === - 1 ) {
2016-12-15 01:13:43 -05:00
log . error ( ` User ${ colors . bold ( name ) } does not exist. ` ) ;
2014-08-24 20:19:03 -04:00
return ;
}
2016-09-20 01:33:09 -04:00
var child _spawn = child . spawn (
2014-10-09 04:27:36 -04:00
process . env . EDITOR || "vi" ,
2016-05-08 02:21:31 -04:00
[ Helper . getUserConfigPath ( name ) ] ,
2014-08-24 20:19:03 -04:00
{ stdio : "inherit" }
) ;
2016-09-20 01:33:09 -04:00
child _spawn . on ( "error" , function ( ) {
2016-12-15 01:13:43 -05:00
log . error ( ` Unable to open ${ colors . green ( Helper . getUserConfigPath ( name ) ) } . ${ colors . bold ( "$EDITOR" ) } is not set, and ${ colors . bold ( "vi" ) } was not found. ` ) ;
2016-09-20 01:33:09 -04:00
} ) ;
2014-08-24 20:19:03 -04:00
} ) ;