Files
node/tools/eslint/node_modules/shelljs/src/cd.js
T
silverwind 128f582558 tools: update ESLint to 2.7.0
PR-URL: https://github.com/nodejs/node/pull/6132
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
2016-04-26 12:15:57 -07:00

29 lines
699 B
JavaScript

var fs = require('fs');
var common = require('./common');
//@
//@ ### cd([dir])
//@ Changes to directory `dir` for the duration of the script. Changes to home
//@ directory if no argument is supplied.
function _cd(options, dir) {
if (!dir)
dir = common.getUserHome();
if (dir === '-') {
if (!common.state.previousDir)
common.error('could not find previous directory');
else
dir = common.state.previousDir;
}
if (!fs.existsSync(dir))
common.error('no such file or directory: ' + dir);
if (!fs.statSync(dir).isDirectory())
common.error('not a directory: ' + dir);
common.state.previousDir = process.cwd();
process.chdir(dir);
}
module.exports = _cd;