Skip to content

Commit

Permalink
adding basic editor support
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Feb 27, 2017
1 parent d8cdbb1 commit 05bd8ba
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Change Log

### upcoming (2017/02/26 20:38 +00:00)
### upcoming (2017/02/27 15:43 +00:00)
- [d8cdbb1](https://github.com/carsdotcom/bitcar/commit/d8cdbb10e76f24f63f787c2f7389e093fb508e11) adding test watch (@machellerogden)
- [8614f2f](https://github.com/carsdotcom/bitcar/commit/8614f2f04e863d25523338fc24efdfd015d6c1b9) more tests (@machellerogden)
- [6cf9aa3](https://github.com/carsdotcom/bitcar/commit/6cf9aa3ac95f76539c3804d9ff9b7dda18b6d0d2) adding tests (@machellerogden)

Expand Down
3 changes: 2 additions & 1 deletion argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = require('minimist')(process.argv.slice(2), {
alias: {
version: 'v',
open: 'o',
refresh: 'r'
refresh: 'r',
edit: 'e'
}
});
8 changes: 6 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ function cli(options) {
return require('./setup')();
}

if (_.isString(options.completions) || _.isString(options.open)) {
searchTerm = options.completions || options.open;
if (_.isString(options.completions)) {
searchTerm = options.completions;
} else if (_.isString(options.open)) {
searchTerm = options.open;
} else if (_.isString(options.edit)) {
searchTerm = options.edit;
} else if (options['clone-all'] || options['force-latest']) {
if (_.isString(options['clone-all'])) {
searchTerm = options['clone-all'];
Expand Down
13 changes: 11 additions & 2 deletions dotfiles/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ function bitcar_cli() {
fi

local target="$HOME/.bitcar/.bitcar_target"
bitcar "$@" && if [ -f "$target" ]; then cd "$(cat "$target")" && rm "$target"; fi

if bitcar "$@" && [ -f "$target" ]; then
cd "$(cat "$target")"
if [ "$1" = "--edit" ] || [ "$2" = "--edit" ] || [ "$1" = "-e" ] || [ "$2" = "-e" ]; then
if [ -n "$BITCAR_EDITOR_CMD" ]; then
$BITCAR_EDITOR_CMD "$(cat "$target")/"
fi
fi
rm "$target"
fi
}
alias <%= alias %>=bitcar_cli
alias bit=bitcar_cli
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"changelog": "./node_modules/.bin/github-changes -o carsdotcom -r bitcar",
"generate-and-stage-changelog": "npm run changelog && git add -A",
"coverage": "rm -rf coverage && node node_modules/.bin/istanbul cover -x \"test/**/*.js\" --dir=\"coverage\" --root=\"./\" node_modules/.bin/_mocha -- \"test/**/*.js\"",
"check-coverage": "npm run coverage && ./node_modules/.bin/istanbul check-coverage --root=\"./coverage\" --statement 60 --function 70 --branch 50"
"check-coverage": "npm run coverage && ./node_modules/.bin/istanbul check-coverage --root=\"./coverage\" --statement 60 --function 70 --branch 45"
},
"contributors": [
{
Expand Down
9 changes: 8 additions & 1 deletion setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,21 @@ function setup() {
name: 'bitbucketServerHost',
message: 'Please enter your Bitbucket Server domain (NOTE: there is no support for bitbucket.org at this time):',
when: (answers) => answers.drivers.indexOf('bitbucket-server') >= 0
},
{
type: 'input',
name: 'editorCmd',
message: 'Please enter the terminal command you\'d like to use for viewing/edit files:',
default: 'vim',
}
]).then((answers) => {
return new Promise((resolve, reject) => {
const path = require('path');

const profileContent = `
# begin bitcar
export BITCAR_WORKSPACE_DIR='${answers.workspaceDir}'
export BITCAR_WORKSPACE_DIR="${answers.workspaceDir}"
export BITCAR_EDITOR_CMD="${answers.editorCmd}"
source $HOME/.bitcar/cli.sh
source $HOME/.bitcar/completions.sh
# end bitcar`;
Expand Down
39 changes: 39 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,44 @@ describe('the bitcar cli', () => {
});
});
});
describe('edit option', () => {
describe('with a search term', () => {
describe('for existing entry', () => {
it('should find existing entry for the search term in the cache - bitcar', () => {
return cli({ _: [ ], edit: 'bitcar' })
.then((result) => {
const resultValidation = schemas.result.validate(result);
expect(resultValidation.error).to.be.a('null');
});
});
it('regardless of order, find existing entry for the search term in the cache - bitcar', () => {
return cli({ _: [ 'bitcar' ], edit: true })
.then((result) => {
const resultValidation = schemas.result.validate(result);
expect(resultValidation.error).to.be.a('null');
});
});
});
describe('for non-existant entry', () => {
it('should exit non-zero with a message of "No results."', () => {
return expect(cli({ _: [ 'doesnotexist' ] })).to.eventually.be.rejectedWith('No results.');
});
});
});
describe('without a search term', () => {
describe('when current working directory corresponds to an entry in the cache', () => {
beforeEach(() => {
sandbox.stub(process, 'cwd', () => '/Users/macheller-ogden/repos/github.com/carsdotcom/bitcar');
});
it('should find existing entry for the search term in the cache - bitcar', () => {
return cli({ _: [ ], edit: true })
.then((result) => {
const resultValidation = schemas.result.validate(result);
expect(resultValidation.error).to.be.a('null');
});
});
});
});
});
});

0 comments on commit 05bd8ba

Please sign in to comment.