Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[Botskills] Fix list command #1248

Merged
merged 2 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 25 additions & 20 deletions lib/typescript/botskills/src/botskills-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ function showErrorHelp(): void {
process.exit(1);
}

function checkSkillsFile(skillsFile: string): boolean {
const skillsFilePath: string = isAbsolute(skillsFile) ? skillsFile : join(resolve('./'), skillsFile);
if (!existsSync(skillsFilePath)) {

return false;
}

return true;
}

const logger: ILogger = new ConsoleLogger();

program.Command.prototype.unknownOption = (flag: string): void => {
Expand All @@ -31,42 +41,37 @@ program
.name('botskills list')
.description('List all the Skills connected to your assistant')
.option('-f, --skillsFile <path>', 'Path to assistant Skills configuration file')
.option('--cs', 'Determine your assistant project structure to be a CSharp-like structure')
.option('--ts', 'Determine your assistant project structure to be a TypeScript-like structure')
.option('--verbose', '[OPTIONAL] Output detailed information about the processing of the tool')
.action((cmd: program.Command, actions: program.Command) => undefined);

const args: program.Command = program.parse(process.argv);

logger.isVerbose = args.verbose;

// cs and ts validation
const csAndTsValidationResult: string = validatePairOfArgs(args.cs, args.ts);
if (csAndTsValidationResult) {
logger.error(
csAndTsValidationResult.replace('{0}', 'cs')
.replace('{1}', 'ts')
);
process.exit(1);
}

// skillsFile validation
if (!args.skillsFile) {
args.skillsFile = args.ts ? join('src', 'skills.json') : 'skills.json';
args.skillsFile = join('src', 'skills.json');
if (!checkSkillsFile(args.skillsFile)) {
args.skillsFile = 'skills.json';
if (!checkSkillsFile(args.skillsFile)) {
logger.error(`The 'skillsFile' argument is absent or leads to a non-existing file.
Please make sure to provide a valid path to your Assistant Skills configuration file.`);
process.exit(1);
}
}
} else if (extname(args.skillsFile) !== '.json') {
logger.error(`The 'skillsFile' argument should be a JSON file.`);
process.exit(1);
}

const skillsFilePath: string = isAbsolute(args.skillsFile) ? args.skillsFile : join(resolve('./'), args.skillsFile);
if (!existsSync(skillsFilePath)) {
logger.error(`The 'skillsFile' argument is absent or leads to a non-existing file.
} else {
if (!checkSkillsFile(args.skillsFile)) {
logger.error(`The 'skillsFile' argument is absent or leads to a non-existing file.
Please make sure to provide a valid path to your Assistant Skills configuration file.`);
process.exit(1);
process.exit(1);
}
}

const configuration: IListConfiguration = {
skillsFile: skillsFilePath,
skillsFile: isAbsolute(args.skillsFile) ? args.skillsFile : join(resolve('./'), args.skillsFile),
logger: logger
};

Expand Down
41 changes: 28 additions & 13 deletions lib/typescript/botskills/src/functionality/listSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,40 @@
import { ConsoleLogger, ILogger} from '../logger';
import { IListConfiguration, ISkillFIle, ISkillManifest } from '../models';

export async function listSkill(configuration: IListConfiguration): Promise<void> {
export async function listSkill(configuration: IListConfiguration): Promise<boolean> {
if (configuration.logger) {
logger = configuration.logger;
}

// Take VA Skills configurations
//tslint:disable-next-line:non-literal-require
const assistantSkillsFile: ISkillFIle = require(configuration.skillsFile);
const assistantSkills: ISkillManifest[] = assistantSkillsFile.skills;
try {
// Take VA Skills configurations
//tslint:disable-next-line:non-literal-require
const assistantSkillsFile: ISkillFIle = require(configuration.skillsFile);
if (!assistantSkillsFile) {
return false;
} else if (!assistantSkillsFile.skills) {
return false;
}
const assistantSkills: ISkillManifest[] = assistantSkillsFile.skills;

if (assistantSkills.length < 1) {
logger.message('There are no Skills connected to the assistant.');
} else {
let message: string = `The skills already connected to the assistant are the following:`;
assistantSkills.forEach((skillManifest: ISkillManifest) => {
message += `\n\t- ${skillManifest.name}`;
});
if (assistantSkills.length < 1) {
logger.message('There are no Skills connected to the assistant.');

logger.message(message);
return false;
} else {
let message: string = `The skills already connected to the assistant are the following:`;
assistantSkills.forEach((skillManifest: ISkillManifest) => {
message += `\n\t- ${skillManifest.name}`;
});

logger.message(message);
}

return true;
} catch (err) {
logger.error(`There was an error while listing the Skills connected to your assistant:\n ${err}`);

return false;
}
}

Expand Down