Skip to content

Commit

Permalink
feat: add hints to the find command when input empty repo name (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan authored and popomore committed Dec 14, 2018
1 parent ceea33a commit 4cbe392
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/command/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class FindCommand extends BaseCommand {

* _run(cwd, [ repo ]) {
const keys = Object.keys(yield this.cache.get());
if (!repo) {
this.logger.error('Please specify the repo name:');
this.childLogger.error(chalk.white('For example:'), chalk.green('projj find', chalk.yellow('example')));
return;
}
let matched = keys.filter(key => key.endsWith(repo.replace(/^\/?/, '/')));
if (!matched.length) matched = keys.filter(key => key.indexOf(repo) >= 0);

Expand Down
12 changes: 12 additions & 0 deletions test/projj_find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ describe('test/projj_find.test.js', () => {
afterEach(mm.restore);
afterEach(() => rimraf(tmp));


it('should to prompt if the input is empty', done => {
const home = path.join(fixtures, 'find');
mm(process.env, 'HOME', home);
coffee.fork(binfile, [ 'find', '' ])
.expect('stderr', new RegExp('Please specify the repo name:'))
.expect('stderr', new RegExp('For example: projj find example'))
.expect('code', 0)
.end(done);
});


it('should find endsWith egg', done => {
const home = path.join(fixtures, 'find');
mm(process.env, 'HOME', home);
Expand Down

0 comments on commit 4cbe392

Please sign in to comment.