mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
refactor(socket) onCloudCmd, onCD: rm pSocket
This commit is contained in:
parent
86fd6cd917
commit
3f4ed02f40
1 changed files with 25 additions and 20 deletions
|
|
@ -127,11 +127,13 @@
|
|||
Util.log(connName + pCommand);
|
||||
|
||||
if (Util.isContainStrAtBegin(pCommand, CLOUDCMD))
|
||||
lRet = onCloudCmd(pCommand, pSocket);
|
||||
lRet = onCloudCmd(pCommand);
|
||||
else if( Util.isContainStrAtBegin(pCommand, 'cd ') )
|
||||
lRet = onCD(pCommand, pSocket);
|
||||
|
||||
if (!lRet) {
|
||||
lRet = onCD(pCommand);
|
||||
|
||||
if (lRet)
|
||||
jsonSend(pSocket, lRet);
|
||||
else {
|
||||
/* if we on windows and command is build in
|
||||
* change code page to unicode becouse
|
||||
* windows use unicode on non English versions
|
||||
|
|
@ -229,7 +231,7 @@
|
|||
cmd.on('error', Util.retFalse);
|
||||
}
|
||||
|
||||
function onCloudCmd(pCommand, pSocket) {
|
||||
function onCloudCmd(pCommand) {
|
||||
var lRet;
|
||||
|
||||
pCommand = Util.removeStr(pCommand, CLOUDCMD);
|
||||
|
|
@ -239,27 +241,29 @@
|
|||
|
||||
if( Util.isContainStrAtBegin(pCommand, 'update') && update ) {
|
||||
update.get();
|
||||
lRet = true;
|
||||
lRet = {
|
||||
stdout: Util.addNewLine('update: ok')
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if( Util.strCmp(pCommand, 'exit') )
|
||||
process.exit();
|
||||
}
|
||||
else {
|
||||
jsonSend(pSocket, {
|
||||
lRet = {
|
||||
stdout : CLOUDCMD + ' exit \n' +
|
||||
CLOUDCMD + ' update \n',
|
||||
stderr : null
|
||||
});
|
||||
|
||||
lRet = true;
|
||||
};
|
||||
}
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
function onCD(pCommand, pSocket) {
|
||||
var lRet, lDir, lHome, lError;
|
||||
function onCD(pCommand) {
|
||||
var lRet, lDir, lHome, lError,
|
||||
lMsg = '';
|
||||
|
||||
lDir = Util.removeStr(pCommand, 'cd ');
|
||||
lHome = process.env.HOME;
|
||||
|
|
@ -271,15 +275,16 @@
|
|||
process.chdir(lDir);
|
||||
});
|
||||
|
||||
if (!lError)
|
||||
lRet = true;
|
||||
else {
|
||||
lError = Util.stringifyJSON(lError);
|
||||
|
||||
jsonSend(pSocket, {
|
||||
stderr: lError
|
||||
});
|
||||
if (lError) {
|
||||
lError = Util.stringifyJSON(lError);
|
||||
lMsg = lError;
|
||||
}
|
||||
|
||||
lRet = {
|
||||
stderr: lMsg
|
||||
};
|
||||
|
||||
return lRet;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue