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

refactor: rename category to cmdCategory in Command class #544

Merged
merged 3 commits into from
Jul 27, 2022
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
2 changes: 1 addition & 1 deletion __tests__/lib/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('utils', () => {
expect(typeof cmd.command === 'string' && cmd.command.length !== 0).toBe(true);
expect(typeof cmd.usage === 'string' && cmd.usage.length !== 0).toBe(true);
expect(typeof cmd.description === 'string' && cmd.usage.description !== 0).toBe(true);
expect(typeof cmd.category === 'string' && cmd.usage.category !== 0).toBe(true);
expect(typeof cmd.cmdCategory === 'string' && cmd.usage.cmdCategory !== 0).toBe(true);
expect(typeof cmd.position === 'number' && cmd.usage.position !== 0).toBe(true);
expect(Array.isArray(cmd.args)).toBe(true);
expect(typeof cmd.run === 'function').toBe(true);
Expand Down
4 changes: 3 additions & 1 deletion bin/rdme
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env node
/* eslint-disable no-console */
const chalk = require('chalk');
const core = require('@actions/core');

Expand All @@ -18,12 +17,14 @@ updateNotifier({ pkg }).notify();
*/
if (!isSupportedNodeVersion(process.version)) {
const message = `We're sorry, this release of rdme does not support Node.js ${process.version}. We support the following versions: ${pkg.engines.node}`;
// eslint-disable-next-line no-console
console.error(chalk.red(`\n${message}\n`));
process.exit(1);
}

require('../src')(process.argv.slice(2))
.then(msg => {
// eslint-disable-next-line no-console
if (msg) console.log(msg);
return process.exit(0);
})
Expand All @@ -46,6 +47,7 @@ require('../src')(process.argv.slice(2))
return core.setFailed(message);
}

// eslint-disable-next-line no-console
console.error(chalk.red(`\n${message}\n`));
return process.exit(1);
});
2 changes: 1 addition & 1 deletion src/cmds/categories/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class CategoriesCreateCommand {
this.command = 'categories:create';
this.usage = 'categories:create <title> [options]';
this.description = 'Create a category with the specified title and guide in your ReadMe project';
this.category = 'categories';
this.cmdCategory = 'categories';
this.position = 2;

this.hiddenargs = ['title'];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class CategoriesCommand {
this.command = 'categories';
this.usage = 'categories [options]';
this.description = 'Get all categories in your ReadMe project';
this.category = 'categories';
this.cmdCategory = 'categories';
this.position = 1;

this.args = [
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/changelogs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class ChangelogsCommand {
this.command = 'changelogs';
this.usage = 'changelogs <folder> [options]';
this.description = 'Sync a folder of Markdown files to your ReadMe project as Changelog posts.';
this.category = 'changelogs';
this.cmdCategory = 'changelogs';
this.position = 1;

this.hiddenArgs = ['folder'];
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports = class ChangelogsCommand {

const updatedDocs = await Promise.all(
files.map(async filename => {
return pushDoc(key, undefined, dryRun, filename, this.category);
return pushDoc(key, undefined, dryRun, filename, this.cmdCategory);
})
);

Expand Down
4 changes: 2 additions & 2 deletions src/cmds/changelogs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class SingleChangelogCommand {
this.command = 'changelogs:single';
this.usage = 'changelogs:single <file> [options]';
this.description = 'Sync a single Markdown file to your ReadMe project as a Changelog post.';
this.category = 'changelogs';
this.cmdCategory = 'changelogs';
this.position = 3;

this.hiddenArgs = ['filePath'];
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = class SingleChangelogCommand {
return Promise.reject(new Error('The file path specified is not a markdown file.'));
}

const createdDoc = await pushDoc(key, undefined, dryRun, filePath, this.category);
const createdDoc = await pushDoc(key, undefined, dryRun, filePath, this.cmdCategory);

return chalk.green(createdDoc);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/docs/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = class EditDocsCommand {
this.command = 'docs:edit';
this.usage = 'docs:edit <slug> [options]';
this.description = 'Edit a single file from your ReadMe project without saving locally.';
this.category = 'docs';
this.cmdCategory = 'docs';
this.position = 2;

this.hiddenArgs = ['slug'];
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = class DocsCommand {
this.command = 'docs';
this.usage = 'docs <folder> [options]';
this.description = 'Sync a folder of Markdown files to your ReadMe project.';
this.category = 'docs';
this.cmdCategory = 'docs';
this.position = 1;

this.hiddenArgs = ['folder'];
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = class DocsCommand {

const updatedDocs = await Promise.all(
files.map(async filename => {
return pushDoc(key, selectedVersion, dryRun, filename, this.category);
return pushDoc(key, selectedVersion, dryRun, filename, this.cmdCategory);
})
);

Expand Down
4 changes: 2 additions & 2 deletions src/cmds/docs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = class SingleDocCommand {
this.command = 'docs:single';
this.usage = 'docs:single <file> [options]';
this.description = 'Sync a single Markdown file to your ReadMe project.';
this.category = 'docs';
this.cmdCategory = 'docs';
this.position = 3;

this.hiddenArgs = ['filePath'];
Expand Down Expand Up @@ -62,7 +62,7 @@ module.exports = class SingleDocCommand {

debug(`selectedVersion: ${selectedVersion}`);

const createdDoc = await pushDoc(key, selectedVersion, dryRun, filePath, this.category);
const createdDoc = await pushDoc(key, selectedVersion, dryRun, filePath, this.cmdCategory);

return chalk.green(createdDoc);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = class LoginCommand {
this.command = 'login';
this.usage = 'login [options]';
this.description = 'Login to a ReadMe project.';
this.category = 'admin';
this.cmdCategory = 'admin';
this.position = 1;

this.args = [
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class LogoutCommand {
this.command = 'logout';
this.usage = 'logout';
this.description = 'Logs the currently authenticated user out of ReadMe.';
this.category = 'admin';
this.cmdCategory = 'admin';
this.position = 2;

this.args = [];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = class OASCommand {
this.command = 'oas';
this.usage = 'oas';
this.description = 'Helpful OpenAPI generation tooling. [inactive]';
this.category = 'utilities';
this.cmdCategory = 'utilities';
this.position = 1;

this.args = [];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class OpenCommand {
this.command = 'open';
this.usage = 'open';
this.description = 'Open your current ReadMe project in the browser.';
this.category = 'utilities';
this.cmdCategory = 'utilities';
this.position = 2;

this.args = [];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class OpenAPICommand {
this.command = 'openapi';
this.usage = 'openapi [file] [options]';
this.description = 'Upload, or resync, your OpenAPI/Swagger definition to ReadMe.';
this.category = 'apis';
this.cmdCategory = 'apis';
this.position = 1;

this.hiddenArgs = ['token', 'spec'];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class ValidateCommand {
this.command = 'validate';
this.usage = 'validate [file] [options]';
this.description = 'Validate your OpenAPI/Swagger definition.';
this.category = 'apis';
this.cmdCategory = 'apis';
this.position = 2;

this.hiddenArgs = ['spec'];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/versions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class CreateVersionCommand {
this.command = 'versions:create';
this.usage = 'versions:create --version=<version> [options]';
this.description = 'Create a new version for your project.';
this.category = 'versions';
this.cmdCategory = 'versions';
this.position = 2;

this.hiddenArgs = ['version'];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/versions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class DeleteVersionCommand {
this.command = 'versions:delete';
this.usage = 'versions:delete --version=<version> [options]';
this.description = 'Delete a version associated with your ReadMe project.';
this.category = 'versions';
this.cmdCategory = 'versions';
this.position = 4;

this.hiddenArgs = ['version'];
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/versions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class VersionsCommand {
this.command = 'versions';
this.usage = 'versions [options]';
this.description = 'List versions available in your project or get a version by SemVer (https://semver.org/).';
this.category = 'versions';
this.cmdCategory = 'versions';
this.position = 1;

this.args = [
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/versions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class UpdateVersionCommand {
this.command = 'versions:update';
this.usage = 'versions:update --version=<version> [options]';
this.description = 'Update an existing version for your project.';
this.category = 'versions';
this.cmdCategory = 'versions';
this.position = 3;

this.args = [
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/whoami.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class WhoAmICommand {
this.command = 'whoami';
this.usage = 'whoami';
this.description = 'Displays the current user and project authenticated with ReadMe.';
this.category = 'admin';
this.cmdCategory = 'admin';
this.position = 3;

this.args = [];
Expand Down
6 changes: 3 additions & 3 deletions src/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.listByCategory = () => {
const categories = exports.getCategories();
const cmds = exports.list();
cmds.forEach(c => {
categories[c.command.category].commands.push({
categories[c.command.cmdCategory].commands.push({
name: c.command.command,
description: c.command.description,
position: c.command.position,
Expand All @@ -32,9 +32,9 @@ exports.listByCategory = () => {
return categories;
};

exports.getSimilar = (category, excludeCommand) => {
exports.getSimilar = (cmdCategory, excludeCommand) => {
const categories = exports.listByCategory();
return categories[category].commands.filter(cmd => cmd.name !== excludeCommand);
return categories[cmdCategory].commands.filter(cmd => cmd.name !== excludeCommand);
};

exports.list = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ exports.commandUsage = cmd => {
},
];

const similarCommands = commands.getSimilar(cmd.category, cmd.command);
const similarCommands = commands.getSimilar(cmd.cmdCategory, cmd.command);
if (similarCommands.length) {
helpContent.push({
header: 'Related commands',
Expand Down