refactor: rename cli

This commit is contained in:
Karl-Philipp Wulfert
2019-01-17 13:29:23 +01:00
parent 48c34d9e1f
commit 98d58fa472
2 changed files with 1 additions and 1 deletions

71
src/cli.ts Normal file
View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Api} from '@openstapps/gitlab-api';
import {Logger} from '@openstapps/logger';
import * as commander from 'commander';
import {existsSync, readFileSync} from 'fs';
import {join} from 'path';
import {GITLAB_API_URL} from './configuration';
import {report} from './tasks/report';
import {tidy} from './tasks/tidy';
import {unlabel} from './tasks/unlabel';
const logger = new Logger();
// add default handler for unhandled rejections
process.on('unhandledRejection', (err) => {
logger.error('UNHANDLED REJECTION', err.stack);
process.exit(1);
});
// check that environment variable GITLAB_PRIVATE_TOKEN is set
if (typeof process.env.GITLAB_PRIVATE_TOKEN !== 'string' || process.env.GITLAB_PRIVATE_TOKEN.length === 0) {
logger.error('Environment variable GITLAB_PRIVATE_TOKEN is not set!');
process.exit(1);
}
const gitlabApi = new Api(GITLAB_API_URL, process.env.GITLAB_PRIVATE_TOKEN as string);
if (existsSync(join(__dirname, 'package.json'))) {
commander.version(JSON.parse(readFileSync(join(__dirname, '..', 'package.json')).toString()).version);
}
commander
.command('report <label>')
.action(async (label: string) => {
await report(gitlabApi, label);
logger.ok('Done!');
});
commander
.command('unlabel')
.action(async () => {
await unlabel(gitlabApi);
logger.ok('Done!');
});
commander
.command('tidy')
.action(async () => {
await tidy(gitlabApi);
logger.ok('Done!');
});
commander
.parse(process.argv);
if (commander.args.length < 1) {
commander.help();
}