From 417ad71ef848d956e317e134d263687f1e59bffc Mon Sep 17 00:00:00 2001 From: svoboda-rabstvo Date: Tue, 28 May 2019 23:21:12 +0300 Subject: [PATCH] feat: add public models interfaces --- index.ts | 10 +++++- src/interface/Argument.ts | 64 +++++++++++++++++++++++++++++++++++++++ src/interface/Command.ts | 22 ++++++++++++++ src/interface/Section.ts | 15 +++++++++ src/interface/Usage.ts | 21 +++++++++++++ src/models/argument.ts | 4 +-- src/models/command.ts | 4 +-- src/models/section.ts | 3 +- src/models/usage.ts | 3 +- 9 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 src/interface/Argument.ts create mode 100644 src/interface/Command.ts create mode 100644 src/interface/Section.ts create mode 100644 src/interface/Usage.ts diff --git a/index.ts b/index.ts index 0988c06..0d83486 100644 --- a/index.ts +++ b/index.ts @@ -5,6 +5,14 @@ import {Section} from './src/models/section'; import {Argument} from './src/models/argument'; import {ArgumentType} from './src/types/argumentType'; +import { UsageInterface } from './src/interface/Usage'; +import { SectionInterface } from './src/interface/Section'; +import { CommandInterface } from './src/interface/Command'; +import { ArgumentInterface } from './src/interface/Argument'; + // tslint:disable-next-line:no-default-export export default UsageParser; -export {Usage, Group, Section, Argument, ArgumentType}; +export { + Usage, Group, Section, Argument, ArgumentType, + UsageInterface, SectionInterface, CommandInterface, ArgumentInterface +}; diff --git a/src/interface/Argument.ts b/src/interface/Argument.ts new file mode 100644 index 0000000..e4c3681 --- /dev/null +++ b/src/interface/Argument.ts @@ -0,0 +1,64 @@ +import { UsageProperty } from "./UsageProperty"; +import { ArgumentType } from "../types/argumentType"; + +export interface ArgumentInterface extends UsageProperty { + /** + * The full name of the argument + * @type {?string | undefined} + */ + longName?: string | undefined; + + /** + * The short name of the argument + * @type {?string | undefined} + */ + shortName?: string | undefined; + + /** + * The description of the argument + * @type {?string | undefined} + */ + description? : string | undefined; + + /** + * The type of argument + * @type {ArgumentType | undefined} + */ + type: ArgumentType | undefined; + + /** + * The possible values of argument + * @type {?string[] | undefined} + */ + values?: string[] | undefined; + + /** + * The default value of argument + * @type {?string | undefined} + */ + default?: string | undefined; + + /** + * The argument is required + * @type {?boolean | undefined} + */ + required?: boolean | undefined; + + /** + * The argument has value + * @type {?boolean | undefined} + */ + hasValue?: boolean | undefined; + + /** + * The delimiter of argument + * @type {?string | undefined} + */ + delimiter?: string | undefined; + + /** + * The argument has deprecated + * @type {?boolean | undefined} + */ + deprecated?: boolean | undefined; +} diff --git a/src/interface/Command.ts b/src/interface/Command.ts new file mode 100644 index 0000000..0c4ea09 --- /dev/null +++ b/src/interface/Command.ts @@ -0,0 +1,22 @@ +import { UsageInterface } from "./Usage"; +import { UsageProperty } from "./UsageProperty"; + +export interface CommandInterface extends UsageProperty { + /** + * The command name + * @type {string} + */ + command: string | undefined; + + /** + * The command description + * @type {?string | undefined} + */ + description?: string | undefined; + + /** + * The commands usage + * @type {?Usage | undefined} + */ + usage?: UsageInterface | undefined; +} diff --git a/src/interface/Section.ts b/src/interface/Section.ts new file mode 100644 index 0000000..7f7796d --- /dev/null +++ b/src/interface/Section.ts @@ -0,0 +1,15 @@ +import { UsageProperty } from "./UsageProperty"; + +export interface SectionInterface { + /** + * Name of section + * @type {string | undefined} + */ + name?: string | undefined; + + /** + * Array of properties + * @type {string[]} + */ + properties: UsageProperty[]; +} diff --git a/src/interface/Usage.ts b/src/interface/Usage.ts new file mode 100644 index 0000000..e0ec1e3 --- /dev/null +++ b/src/interface/Usage.ts @@ -0,0 +1,21 @@ +import { SectionInterface } from "./Section"; + +export interface UsageInterface { + /** + * Array of Section object + * @type {Section[]} + */ + sections: SectionInterface[]; + + /** + * Global delimiter of usage's doc + * @type {?string | undefined} + */ + delimiter?: string | undefined; + + /** + * Examples of usage + * @type {?string[] | undefined} + */ + examples?: string[] | undefined; +} diff --git a/src/models/argument.ts b/src/models/argument.ts index 3c640a3..e863a40 100644 --- a/src/models/argument.ts +++ b/src/models/argument.ts @@ -1,12 +1,12 @@ import {config} from '../config'; import {ArgumentType} from '../types/argumentType'; import {ArgumentTypes} from './argumentTypes'; -import {UsageProperty} from '../interface/UsageProperty'; +import { ArgumentInterface } from '../interface/Argument'; import '../extensions/String'; /** Argument object of usage's doc */ -export class Argument implements UsageProperty { +export class Argument implements ArgumentInterface { /** * The full name of the argument * @type {?string | undefined} diff --git a/src/models/command.ts b/src/models/command.ts index 0d33bc1..2d5bc4a 100644 --- a/src/models/command.ts +++ b/src/models/command.ts @@ -1,10 +1,10 @@ import {Usage} from "./usage"; -import {UsageProperty} from '../interface/UsageProperty'; +import { CommandInterface } from "../interface/Command"; /** * The command with name, description and usage, if they exist */ -class Command implements UsageProperty { +class Command implements CommandInterface { /** * The command name diff --git a/src/models/section.ts b/src/models/section.ts index 8d1767a..9023dae 100644 --- a/src/models/section.ts +++ b/src/models/section.ts @@ -1,9 +1,10 @@ import {UsageProperty} from "../interface/UsageProperty"; +import { SectionInterface } from "../interface/Section"; import '../interface/String'; /** The section with properties of usage's doc */ -export class Section { +export class Section implements SectionInterface { /** * Name of section diff --git a/src/models/usage.ts b/src/models/usage.ts index 456bc9d..f126588 100644 --- a/src/models/usage.ts +++ b/src/models/usage.ts @@ -1,9 +1,10 @@ import {Section} from './section'; +import { UsageInterface } from '../interface/Usage'; /** * The Usage is a Object which contains Section of doc */ -export class Usage { +export class Usage implements UsageInterface { /** * Array of Section object