Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve CLI messages and move them into separate file #40

Merged
merged 18 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 7 additions & 6 deletions src/hooks/context/models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as messages from '../../messages';
export interface Context {
current: string,
store: {
Expand All @@ -15,41 +16,41 @@ export class SpecFileNotFoundError extends Error {
export class ContextFileNotFoundError extends Error {
constructor() {
super();
this.message = 'No contexts saved yet, run asyncapi --help to know more.';
this.message = messages.NO_CONTEXTS_SAVED;
}
}

export class ContextNotFoundError extends Error {
constructor() {
super();
this.message = 'This context key does not exist.';
this.message = messages.CONTEXT_NOT_FOUND;
}
}

export class KeyNotFoundError extends Error {
constructor() {
super();
this.message = 'Key not found.';
this.message = messages.KEY_NOT_FOUND;
}
}

export class DeletingCurrentContextError extends Error {
constructor() {
super();
this.message = 'You are trying to delete a context that is currently in use.';
this.message = messages.DELETING_CURRENT_CONTEXT;
}
}

export class MissingCurrentContextError extends Error {
constructor() {
super();
this.message = 'No context is set as current, please set a current context.';
this.message = messages.MISSING_CURRENT_CONTEXT;
}
}

export class MissingArgumentstError extends Error {
constructor() {
super();
this.message = 'Missing arguments';
this.message = messages.MISSING_ARGUMENTS;
}
}
78 changes: 78 additions & 0 deletions src/messages.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
export const NO_CONTEXTS_SAVED = 'No contexts saved yet, run asyncapi --help to know more';
Souvikns marked this conversation as resolved.
Show resolved Hide resolved

export const CONTEXT_NOT_FOUND = 'This context key does not exists.';
Souvikns marked this conversation as resolved.
Show resolved Hide resolved

export const KEY_NOT_FOUND = 'Key not found';
Souvikns marked this conversation as resolved.
Show resolved Hide resolved

export const DELETING_CURRENT_CONTEXT = 'You are tyring to delete a context that is currently in use.';
Souvikns marked this conversation as resolved.
Show resolved Hide resolved

export const MISSING_CURRENT_CONTEXT = 'No context is set as current, please set a current context.';
Souvikns marked this conversation as resolved.
Show resolved Hide resolved

export const MISSING_ARGUMENTS = 'Missing arguments.';
derberg marked this conversation as resolved.
Show resolved Hide resolved

export interface CommandHelp {
name: string,
usage: string,
shortDescription?: string,
longDescription?: string,
flags?: string[],
commands?: string[]
}

export class Help {
private _helpFlag = '-h, --help display help for command';
private root: CommandHelp = {
name: 'root',
usage: 'asyncapi [options] [command]',
flags: [
this._helpFlag,
'-v, -version output the version number'
]
}

private validate: CommandHelp = {
name: 'validate',
usage: 'asyncapi validate [options]',
shortDescription: 'Validate an asyncapi file',
flags: [
'-f, --file <spec-file-path> Path of the spec file',
'-c, --context <saved-context-name> Context name to use',
'-w, --watch watch mode',
this._helpFlag
]
}

private context: CommandHelp = {
name: 'context',
usage: 'asyncapi context [options] [command]',
Souvikns marked this conversation as resolved.
Show resolved Hide resolved
shortDescription: 'Manage contexts',
flags: [
Souvikns marked this conversation as resolved.
Show resolved Hide resolved
this._helpFlag
],
commands: [
'list list all saved contexts',
'current see current context',
'use <context-name> set a context as current',
'add <context-name> <spec-file-path> add/update context',
'remove <context-name> remove a context'
]
}

rootHelp(): string {
let helpString = '';
helpString += `usage: ${this.root.usage}\n\n`;
helpString += 'options:\n';
if (this.root.flags) {
for (const flag of this.root.flags) {
helpString += ` ${flag} \n`;
}
}

helpString += '\n';

helpString += 'commads:\n';
helpString += ` context [options] [command] ${this.context.shortDescription} \n`;
helpString += ` validate [options] ${this.validate.shortDescription}\n`;
return helpString;
}
}