Merge pull request #306 from nfischer/cd-no-args

feat(cd): cd() (no args) changes to home directory
This commit is contained in:
Ari Porad 2016-01-24 14:11:13 -08:00
commit 361eb93430
3 changed files with 13 additions and 8 deletions

View File

@ -154,8 +154,9 @@ target.bundle = function(argsArray) {
All commands run synchronously, unless otherwise stated.
### cd('dir')
Changes to directory `dir` for the duration of the script
### cd([dir])
Changes to directory `dir` for the duration of the script. Changes to home
directory if no argument is supplied.
### pwd()

View File

@ -2,11 +2,12 @@ var fs = require('fs');
var common = require('./common');
//@
//@ ### cd('dir')
//@ Changes to directory `dir` for the duration of the script
//@ ### 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)
common.error('directory not specified');
dir = common.getUserHome();
if (dir === '-') {
if (!common.state.previousDir)

View File

@ -17,9 +17,6 @@ shell.mkdir('tmp');
// Invalids
//
shell.cd();
assert.ok(shell.error());
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
shell.cd('/adsfasdf'); // dir does not exist
assert.ok(shell.error());
@ -72,4 +69,10 @@ shell.cd('..');
shell.cd('~'); // Change back to home
assert.equal(process.cwd(), common.getUserHome());
// Goes to home directory if no arguments are passed
shell.cd(cur);
shell.cd();
assert.ok(!shell.error());
assert.equal(process.cwd(), common.getUserHome());
shell.exit(123);