Skip to content

Commit

Permalink
build: fix usage printing in build profile
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Genovese <genovese@cmu.edu>
  • Loading branch information
Planeshifter and genovese committed Jul 14, 2023
1 parent efc7238 commit 75832f4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 49 deletions.
45 changes: 2 additions & 43 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Maybe = require( './maybe.js' );
const { summarize
, autoSummarizer
} = require( './graph-summary.js' );
const usageMessage = require( './usage-message.js' );


// Constants
Expand Down Expand Up @@ -189,48 +190,6 @@ function readConfig( clKeys, configFile = homeDirectoryFile( CONFIG_FILE ) ) {
return config;
}

/**
* Prints a usage message to the console showing all available commands.
*/
function printUsage() {
const out = [];
out.push( 'Usage: graphmaker [options]' );
out.push( '' );
out.push( 'Options:' );
out.push( '' );
const rows = Object.keys( clOptions ).map( key => {
const row = [];
const opt = clOptions[ key ];
const arg = opt.type === 'string' ? (' ' + (opt.tag || 'ARG')) : '';
if ( opt.short ) {
row.push( '-'+opt.short+', --'+key+arg );
} else {
row.push( '--'+key+arg );
}
row.push( opt.description );
return row;
});
out.push( table( rows, {
border: getBorderCharacters('void'),
columnDefault: {
paddingLeft: 2,
paddingRight: 2
},
columns: {
0: {
alignment: 'left',
width: 30
},
1: {
alignment: 'left',
width: 50
}
}
}) );
out.push( '' );
return out.join( '\n' );
}

/**
* Processes command line arguments and returns them as a key-value pair object.
* If `width` or `height` values are provided, they are parsed to integers.
Expand Down Expand Up @@ -335,7 +294,7 @@ if ( args.version ) {
console.log( `${VERSION}`);
process.exit( 0 );
} else if ( args.help ) {
console.log( printUsage() );
console.log( usageMessage() );
process.exit( 0 );
}

Expand Down
46 changes: 46 additions & 0 deletions lib/usage-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { table, getBorderCharacters } = require( 'table' );
const clOptions = require( './spec/cli-options.json' );

/**
* Returns a usage message showing all available commands.
*/
function usageMessage() {
const out = [];
out.push( 'Usage: graphmaker [options]' );
out.push( '' );
out.push( 'Options:' );
out.push( '' );
const rows = Object.keys( clOptions ).map( key => {
const row = [];
const opt = clOptions[ key ];
const arg = opt.type === 'string' ? (' ' + (opt.tag || 'ARG')) : '';
if ( opt.short ) {
row.push( '-'+opt.short+', --'+key+arg );
} else {
row.push( '--'+key+arg );
}
row.push( opt.description );
return row;
});
out.push( table( rows, {
border: getBorderCharacters('void'),
columnDefault: {
paddingLeft: 2,
paddingRight: 2
},
columns: {
0: {
alignment: 'left',
width: 30
},
1: {
alignment: 'left',
width: 50
}
}
}) );
out.push( '' );
return out.join( '\n' );
}

module.exports = usageMessage;
6 changes: 3 additions & 3 deletions profiles/build-docs-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
"url": "https://github.com/isle-project/graphmaker/issues"
},
"homepage": "https://github.com/isle-project/graphmaker#readme",
"dependencies": {
"@stdlib/string-base-kebabcase": "^0.0.2"
},
"dependencies": {},
"devDependencies": {
"@stdlib/string-base-kebabcase": "^0.0.2",
"dedent": "^1.0.1",
"json-schema-to-typescript": "^13.0.2",
"markdown-it": "^13.0.1",
"markdown-it-anchor": "^8.6.7",
"nearley": "^2.20.1",
"table": "^6.8.1",
"tailwindcss": "^3.3.2",
"typedoc": "^0.24.8"
},
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const readline = require('readline');
const { execSync } = require('child_process');
const usageMessage = require( './../lib/usage-message.js' );

function contentsInclude( contentFile ) {
return fs.readFileSync( contentFile, 'UTF-8' );
Expand Down Expand Up @@ -84,9 +85,8 @@ function contentsStyles( schemaFileName ) {
return out.join('\n');
}

function outputHelp( command ) {
const help = execSync( `node ${command} --help` ).toString();
return help;
function outputHelp( _ ) {
return usageMessage();
}

const directiveDispatch = {
Expand Down

0 comments on commit 75832f4

Please sign in to comment.