Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cache.json
.nyc_output/
!test/fixtures/hook/.projj/cache.json
!test/fixtures/multiple-directory/.projj/cache.json
.github/
.github/
.DS_Store
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sudo: false

language: node_js
node_js:
- '10'
Expand Down
74 changes: 74 additions & 0 deletions lib/command/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

const chalk = require('chalk');
const clipboardy = require('clipboardy');
const utils = require('../utils');
const BaseCommand = require('../base_command');

class ListCommand extends BaseCommand {

async _run(cwd, [ repo = '' ]) {
const keys = await this.cache.getKeys();

if (!keys.length) {
this.logger.error('Workspace is empty.');
return;
}

let matched = keys;
if (repo) matched = keys.filter(key => key.indexOf(repo) >= 0);
const res = await this.choose(matched);
const key = res.key;
const dir = key;
if (this.config.change_directory) {
/* istanbul ignore next */
if (process.platform === 'darwin') {
const script = utils.generateAppleScript(dir);
this.logger.info(`Change directory to ${dir}`);
await this.runScript(script);
return;
}
this.logger.error('Change directory only supported in darwin');
}
await this.copyPath(repo, dir);
}

async choose(choices) {
const cache = await this.cache.get();
const list = choices.map(key => {
let name = key;
if (this.config.base.length === 1) {
name = key.replace(this.config.base[0], '')
.replace(/^\/+/, '') +
(cache[key]?.desc ? ': ' + cache[key].desc : '');
}
return {
name,
value: key,
};
});
return await this.prompt({
name: 'key',
type: 'rawlist',
message: 'Please select one of the repo',
choices: list,
});
}

async copyPath(repo, dir) {
try {
this.logger.info('find repo %s\'s location: %s', repo, dir);
await clipboardy.write(`cd ${dir}`);
this.logger.info(chalk.green('📋 Copied to clipboard') + ', just use Ctrl+V');
} catch (e) {
this.logger.warn('Fail to copy to clipboard, error: %s', e.message);
}
}

get description() {
return 'List all of repositories';
}

}

module.exports = ListCommand;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clipboardy": "^2.1.0",
"common-bin": "^2.8.3",
"giturl": "^1.0.1",
"inquirer": "^7.0.3",
"inquirer": "^8.2.4",
"mz": "^2.7.0",
"mz-modules": "^2.1.0",
"ora": "^4.0.3",
Expand Down