8000 allow to format list-* task output as list · TailorDev/assignees@afe35fa · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
allow to format list-* task output as list
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Apr 26, 2018
1 parent b1c6cc2 commit afe35fa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
24 changes: 22 additions & 2 deletions bin/assignees
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const updateUserFeatureTask = require('../tasks/updateUserFeature');
const disableProjectTask = require('../tasks/disableProject');
const disableProjectsTask = require('../tasks/disableProjects');
const listOwnersTask = require('../tasks/listOwners');
const listEmailsTask = require('../tasks/listEmails');

const updateUserFeatureAction = operation => async (username, feature) => {
const updateUserFeature = updateUserFeatureTask.configure( 8000 { logger });
Expand Down Expand Up @@ -130,11 +131,30 @@ program
program
.command('project:list-owners')
.description('list all the owners in database')
.action(async () => {
.option('--as-list', 'output as list separated by newlines')
.action(async (options) => {
const listOwners = listOwnersTask.configure({ logger });

try {
await listOwners();
await listOwners(options.asList);
} catch(e) {
logger.error(chalk.red(e.stack));
process.exitCode = 1;
} finally {
mongoose.connection.close();
}
})
;

program
.command('project:list-emails')
.description('list all the emails in database')
.option('--as-list', 'output as list separated by newlines')
.action(async (options) => {
const listEmails = listEmailsTask.configure({ logger });

try {
await listEmails(options.asList);
} catch(e) {
logger.error(chalk.red(e.stack));
process.exitCode = 1;
Expand Down
18 changes: 18 additions & 0 deletions tasks/listEmails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const User = require('../models/User');
const inspect = require('../helpers/inspect');

/**
* config = {
* logger: { info: Function, error: Function },
* }
*/
exports.configure = config => async (asList) => {
const users = await User.find().catch([]);
const emails = [...new Set(users.map((r) => r.email).filter((email) => /@/.test(email)))];

if (asList) {
console.log(emails.join('\n'))
} else {
config.logger.info(inspect(emails));
}
};
8 changes: 6 additions & 2 deletions tasks/listOwners.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ const inspect = require('../helpers/inspect');
* logger: { info: Function, error: Function },
* }
*/
exports.configure = config => async (username) => {
exports.configure = config => async (asList) => {
const repositories = await Repository.find().catch([]);
const owners = [...new Set(repositories.map((r) => r.owner))];

config.logger.info(inspect(owners));
if (asList) {
console.log(owners.join('\n'))
} else {
config.logger.info(inspect(owners));
}
};

0 comments on commit afe35fa

Please sign in to comment.
0