Skip to content

Commit

Permalink
Added commands for version and usage of CLI info, touch #456.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Jul 5, 2024
1 parent 4ffca85 commit 6df5b48
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
22 changes: 18 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,27 @@ const start = async () => {
// Get the CLI arguments
const args = process.argv;

// Print the usage information if no arguments supplied
// Display version information if requested
if (
['-v', '--v', '-version', '--version'].includes(args[args.length - 1])
) {
// Print logo with the version information
return main.printVersion();
}

// Display help information if requested
if (['-h', '--h', '-help', '--help'].includes(args[args.length - 1])) {
// Print logo with the version information
return main.printUsage();
}

// Print logo with a version and usage information if no arguments supplied
if (args.length <= 2) {
main.log(
main.printUsage();
return main.log(
2,
'[cli] The number of provided arguments is too small. Please refer to the section below.'
'[cli] The number of provided arguments is too small. Please refer to the help section above.'
);
return main.printUsage();
}

// Set the options, keeping the priority order of setting values:
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function pairArgumentValue(options, args, defaultConfig) {

// Display the usage for the reference if needed
if (showUsage) {
printUsage(defaultConfig);
printUsage(true);
}

return options;
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { initPool, killPool } from './pool.js';
import { shutdownCleanUp } from './resource_release.js';
import server, { startServer } from './server/server.js';
import { printLogo, printUsage } from './utils.js';
import { printLogo, printVersion, printUsage } from './utils.js';

/**
* Attaches exit listeners to the process, ensuring proper cleanup of resources
Expand Down Expand Up @@ -140,5 +140,6 @@ export default {
mapToNewConfig,
manualConfig,
printLogo,
printVersion,
printUsage
};
39 changes: 33 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { defaultConfig } from '../lib/schemas/config.js';
import { log, logWithStack } from './logger.js';

const MAX_BACKOFF_ATTEMPTS = 6;
const readme = 'https://github.com/highcharts/node-export-server#readme';

export const __dirname = fileURLToPath(new URL('../.', import.meta.url));

Expand Down Expand Up @@ -321,7 +322,7 @@ export const printLogo = (noLogo) => {

// Print text only
if (noLogo) {
console.log(`Starting Highcharts Export Server v${packageVersion}...`);
console.log(`Highcharts Export Server v${packageVersion}`);
return;
}

Expand All @@ -334,17 +335,22 @@ export const printLogo = (noLogo) => {

/**
* Prints the usage information for CLI arguments. If required, it can list
* properties recursively
* properties recursively.
*
* @param {boolean} noLogo - If true, only prints version information without
* the logo.
*/
export function printUsage() {
export function printUsage(noLogo) {
const pad = 48;
const readme = 'https://github.com/highcharts/node-export-server#readme';

// Print the logo and version information
printLogo(noLogo);

// Display readme information
console.log(
'\nUsage of CLI arguments:'.bold,
'\n------',
`\nFor more detailed information, visit the readme at: ${readme.bold.yellow}.`
'\n-----',
`\nFor more detailed information, visit the README file at: ${readme.green}`
);

const cycleCategories = (options) => {
Expand Down Expand Up @@ -383,6 +389,26 @@ export function printUsage() {
console.log('\n');
}

/**
* Prints the Highcharts Export Server logo, version and license information.
*/
export const printVersion = () => {
// Print the logo and version information
printLogo();

// Print the license information
console.log(
'This software requires a valid Highcharts license for commercial use.\n'
.yellow,
'\nFor a full list of CLI options, type:',
'\nhighcharts-export-server --help\n'.green,
'\nIf you do not have a license, one can be obtained here:',
'\nhttps://shop.highsoft.com/\n'.green,
'\nTo customize your installation, please refer to the README file at:',
`\n${readme}\n`.green
);
};

/**
* Rounds a number to the specified precision.
*
Expand Down Expand Up @@ -460,6 +486,7 @@ export default {
isPrivateRangeUrlFound,
optionsStringify,
printLogo,
printVersion,
printUsage,
roundNumber,
toBoolean,
Expand Down

0 comments on commit 6df5b48

Please sign in to comment.