Compare commits
1 commit
5e72bddc83
...
2db82b708d
Author | SHA1 | Date | |
---|---|---|---|
2db82b708d |
2 changed files with 4 additions and 19 deletions
|
@ -2,16 +2,12 @@ import Telme from './telme';
|
|||
import { ArgParser, ERunMode, ISimpleMessageOptions, ITaskOptions, IInitProfileOptions } from './utils';
|
||||
import Config, { IProfileConfig } from './config/config';
|
||||
import Init from './flows/init'
|
||||
const { version } = require('../package.json');
|
||||
|
||||
async function main() {
|
||||
const parsed = ArgParser.parse(process.argv);
|
||||
let config: IProfileConfig;
|
||||
let options: any;
|
||||
switch (parsed.mode) {
|
||||
case ERunMode.VERSION:
|
||||
console.log(`[${Config.APP_NAME}] version ${version}`);
|
||||
break;
|
||||
case ERunMode.HELP:
|
||||
printHelp();
|
||||
break;
|
||||
|
@ -38,12 +34,11 @@ async function main() {
|
|||
function printHelp() {
|
||||
const cliFlags = ArgParser.CLI_OPTIONS;
|
||||
const message =
|
||||
`${Config.APP_NAME} v${version} - A CLI Telegram message tool
|
||||
`${Config.APP_NAME} - A CLI Telegram message tool
|
||||
|
||||
[Usage]: $ ${Config.APP_NAME} <telme_options> <?command> <arguments>
|
||||
|
||||
Options:
|
||||
\t ${cliFlags.versionFlags.join(', ')} \t\t Print ${Config.APP_NAME} version.
|
||||
\t ${cliFlags.helpFlags.join(', ')} \t\t This help page.
|
||||
\t ${cliFlags.profileFlags.join(', ')} \t\t Specify a profile to use. This is optional. defaults to 'default' profile.
|
||||
\t ${cliFlags.initFlags.join(', ')} \t\t Will generate a config file for a given profile (defaults to 'default' profile).
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import InvalidArgumentsError from "../errors/invalid_arguments.error";
|
||||
|
||||
const CLI_OPTIONS = {
|
||||
versionFlags: ['--version', '-v'],
|
||||
helpFlags: ['--help', '-h'],
|
||||
initFlags: ['--init', '-i'],
|
||||
profileFlags: ['--profile', '-p'],
|
||||
|
@ -14,11 +13,7 @@ export class ArgParser {
|
|||
static parse(testArgs: string[] = null): IRunOptions {
|
||||
let cliArgs = testArgs ? testArgs.slice(2) : process.argv.slice(2);
|
||||
let tokens = tokenize(cliArgs);
|
||||
if (tokens.version) {
|
||||
return {
|
||||
mode: ERunMode.VERSION
|
||||
}
|
||||
} else if (tokens.help) {
|
||||
if (tokens.help) {
|
||||
return {
|
||||
mode: ERunMode.HELP
|
||||
}
|
||||
|
@ -54,16 +49,13 @@ export class ArgParser {
|
|||
function tokenize(args: string[]) {
|
||||
let cliArgs = args;
|
||||
if (!cliArgs.length) throw new InvalidArgumentsError('Missing a command to run');
|
||||
const tokens: ITokenizeArgs = { init: false, help: false, version: false };
|
||||
const tokens: ITokenizeArgs = { init: false, help: false };
|
||||
// ['node', 'execCommand', ...];
|
||||
let mode: ERunMode = ERunMode.TASK_MESSAGE;
|
||||
while (cliArgs.length > 0) {
|
||||
let tokenCursor = 1;
|
||||
const token = cliArgs[0];
|
||||
if (CLI_OPTIONS.versionFlags.indexOf(token) >= 0) {
|
||||
tokens.version = true;
|
||||
return tokens;
|
||||
} else if (CLI_OPTIONS.helpFlags.indexOf(token) >= 0) {
|
||||
if (CLI_OPTIONS.helpFlags.indexOf(token) >= 0) {
|
||||
tokens.help = true;
|
||||
return tokens;
|
||||
} else if (CLI_OPTIONS.initFlags.indexOf(token) >= 0) {
|
||||
|
@ -97,7 +89,6 @@ function tokenize(args: string[]) {
|
|||
}
|
||||
|
||||
interface ITokenizeArgs {
|
||||
version: boolean;
|
||||
help: boolean;
|
||||
profile?: string;
|
||||
init: boolean;
|
||||
|
@ -131,7 +122,6 @@ export interface ITaskOptions extends IBasicOptions {
|
|||
|
||||
|
||||
export enum ERunMode {
|
||||
VERSION,
|
||||
HELP,
|
||||
INIT,
|
||||
SIMPLE_MESSAGE,
|
||||
|
|
Reference in a new issue