Skip to content

Commit

Permalink
Minor code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
siokas committed Apr 13, 2020
1 parent 0047448 commit 0fff2e7
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 145 deletions.
12 changes: 6 additions & 6 deletions AppDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ export default class AppDetails implements AppDetailsAccessors {
/**
* The name of the app.
*
* @public
* @private
* @type {string}
* @memberof AppDetails
*/
_app_name: string;
private _app_name: string;

/**
* The description of the app.
*
* @public
* @private
* @type {string}
* @memberof AppDetails
*/
_app_description: string;
private _app_description: string;

/**
* The version of the app.
*
* @public
* @private
* @type {string}
* @memberof AppDetails
*/
_app_version: string;
private _app_version: string;

/**
* Constructor of AppDetails object.
Expand Down
24 changes: 12 additions & 12 deletions Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { CommandOptions } from "./interfaces.ts";
* @class Command
*/
export default class Command {
/**
* If the command has a required value
* to be passed from the user.
*
* @public
* @type {boolean}
* @memberof Command
*/
public require_command_value = false;

/**
* Holds the short flag (-p)
* One letter command.
Expand Down Expand Up @@ -38,16 +48,6 @@ export default class Command {
*/
private options: CommandOptions;

/**
* If the command has a required value
* to be passed from the user.
*
* @public
* @type {boolean}
* @memberof Command
*/
require_command_value: boolean = false;

/**
* Constructor of Command object.
*
Expand Down Expand Up @@ -82,7 +82,7 @@ export default class Command {
* @memberof Command
*/
private generateCommand() {
let splitedValue = this.options.value.split(" ");
const splitedValue = this.options.value.split(" ");

switch (splitedValue.length) {
case 1:
Expand All @@ -107,7 +107,7 @@ export default class Command {
* @memberof Command
*/
private generateOption() {
let splitedValue: Array<string> = this.splitValue(this.options.value);
const splitedValue: Array<string> = this.splitValue(this.options.value);

switch (splitedValue.length) {
case 1:
Expand Down
148 changes: 74 additions & 74 deletions Denomander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class Denomander extends AppDetails
* @type {boolean}
* @memberof Denomander
*/
private isHelpConfigured: boolean = false;
private isHelpConfigured = false;

/**
* If the user has defined a custom version
Expand All @@ -156,52 +156,21 @@ export default class Denomander extends AppDetails
* @type {boolean}
* @memberof Denomander
*/
private isVersionConfigured: boolean = false;
private isVersionConfigured = false;

/**
* Generate the default options
* (help, version)
*
* @private
* @returns {Denomander}
* @memberof Denomander
*/
private generateDefaultOptions(): Denomander {
return this
.generateHelpOption()
.generateVersionOption();
}

/**
* Generate the default help option
*
* @private
* @returns {Denomander}
* @memberof Denomander
*/
private generateHelpOption(): Denomander {
if (!this.isHelpConfigured) {
this.commands.push(this.help_command);
this.available_default_options.push(this.help_command);
}

return this;
}

/**
* Generate the default version option
* Parses the args.
*
* @private
* @returns {Denomander}
* @memberof Denomander
* @param {any} args
* @memberof Parasable
*/
private generateVersionOption(): Denomander {
if (!this.isVersionConfigured) {
this.commands.push(this.version_command);
this.available_default_options.push(this.version_command);
}
public parse(args: any): void {
this._args = parse(args, { "--": false });

return this;
this
.generateDefaultOptions()
.validateArgs()
.executeCommands();
}

/**
Expand All @@ -213,7 +182,7 @@ export default class Denomander extends AppDetails
* @returns {Denomander}
* @memberof PublicAPI
*/
option(value: string, description: string): Denomander {
public option(value: string, description: string): Denomander {
this.commands.push(new Command({ value, description }));
this.available_options.push(new Command({ value, description }));

Expand All @@ -229,8 +198,8 @@ export default class Denomander extends AppDetails
* @returns {Denomander}
* @memberof PublicAPI
*/
requiredOption(value: string, description: string): Denomander {
let command: Command = new Command(
public requiredOption(value: string, description: string): Denomander {
const command: Command = new Command(
{ value, description, is_required: true },
);
this.commands.push(command);
Expand All @@ -248,8 +217,8 @@ export default class Denomander extends AppDetails
* @returns {Denomander}
* @memberof PublicAPI
*/
command(value: string, description?: string): Denomander {
let new_command: Command = new Command({
public command(value: string, description?: string): Denomander {
const new_command: Command = new Command({
value,
description,
type: "command",
Expand All @@ -268,8 +237,8 @@ export default class Denomander extends AppDetails
* @returns {Denomander}
* @memberof PublicAPI
*/
description(description: string): Denomander {
let command: Command = this.commands.slice(-1)[0];
public description(description: string): Denomander {
const command: Command = this.commands.slice(-1)[0];

if (command) {
command.description = description;
Expand All @@ -286,8 +255,8 @@ export default class Denomander extends AppDetails
* @returns {Denomander}
* @memberof PublicAPI
*/
action(callback: Function): Denomander {
let command: Command = this.commands.slice(-1)[0];
public action(callback: Function): Denomander {
const command: Command = this.commands.slice(-1)[0];

if (command) {
command.action = callback;
Expand All @@ -305,7 +274,7 @@ export default class Denomander extends AppDetails
* @param {Function} callback
* @memberof PublicAPI
*/
on(arg: string, callback: Function): Denomander {
public on(arg: string, callback: Function): Denomander {
this.temp_on_commands.push({ arg, callback });

return this;
Expand All @@ -319,10 +288,10 @@ export default class Denomander extends AppDetails
* @param {string} description
* @memberof PublicAPI
*/
setHelp(command: string, description: string): Denomander {
public setHelp(command: string, description: string): Denomander {
this.help_command = new Command({ value: command, description });

let new_available_default_options = removeCommandFromArray(
const new_available_default_options = removeCommandFromArray(
this.commands,
"help",
);
Expand All @@ -343,15 +312,15 @@ export default class Denomander extends AppDetails
* @param {string} description
* @memberof PublicAPI
*/
setVersion(
public setVersion(
version: string,
command: string,
description: string,
): Denomander {
this.version = version;
this.version_command = new Command({ value: command, description });

let new_available_default_options = removeCommandFromArray(
const new_available_default_options = removeCommandFromArray(
this.commands,
"version",
);
Expand All @@ -363,6 +332,52 @@ export default class Denomander extends AppDetails
return this;
}

/**
* Generate the default options
* (help, version)
*
* @private
* @returns {Denomander}
* @memberof Denomander
*/
private generateDefaultOptions(): Denomander {
return this
.generateHelpOption()
.generateVersionOption();
}

/**
* Generate the default help option
*
* @private
* @returns {Denomander}
* @memberof Denomander
*/
private generateHelpOption(): Denomander {
if (!this.isHelpConfigured) {
this.commands.push(this.help_command);
this.available_default_options.push(this.help_command);
}

return this;
}

/**
* Generate the default version option
*
* @private
* @returns {Denomander}
* @memberof Denomander
*/
private generateVersionOption(): Denomander {
if (!this.isVersionConfigured) {
this.commands.push(this.version_command);
this.available_default_options.push(this.version_command);
}

return this;
}

/**
* It prints out the help doc
*
Expand All @@ -371,10 +386,10 @@ export default class Denomander extends AppDetails
*/
private print_help(): void {
console.log();
console.log(green(bold(this._app_name)));
console.log(green(bold(this.app_name)));
console.log();
console.log(yellow(bold("Description:")));
console.log(this._app_description);
console.log(this.app_description);
console.log();

if (this.available_requiredOptions.length > 0) {
Expand Down Expand Up @@ -470,7 +485,7 @@ export default class Denomander extends AppDetails
* @memberof Denomander
*/
private validateOptionsAndCommands(): Denomander {
for (let key in this._args) {
for (const key in this._args) {
if (key === "length" || !this._args.hasOwnProperty(key)) continue;

if (key == "_") {
Expand Down Expand Up @@ -596,19 +611,4 @@ export default class Denomander extends AppDetails

return this;
}

/**
* Parses the args.
*
* @param {any} args
* @memberof Parasable
*/
parse(args: any): void {
this._args = parse(args, { "--": false });

this
.generateDefaultOptions()
.validateArgs()
.executeCommands();
}
}
Loading

0 comments on commit 0fff2e7

Please sign in to comment.