Skip to content

Commit 15c4022

Browse files
committed
Updates to README to reflect mods to CLI BaseCommand
Signed-off-by: George M Dias <GDIAS@MITRE.ORG>
1 parent f376520 commit 15c4022

File tree

7 files changed

+95
-72
lines changed

7 files changed

+95
-72
lines changed

README.md

+77-62
Large diffs are not rendered by default.

src/commands/generate/inspec_profile.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import YAML from 'yaml'
1313

1414
export default class InspecProfile extends BaseCommand<typeof InspecProfile> {
1515
static readonly usage =
16-
'<%= command.id %> -i <stig-xccdf-xml> [-o <output-folder>] [-h] [-m <metadata-json>] ' +
17-
'[-T (rule|group|cis|version)] [-s] [-L (info|warn|debug|verbose)]'
16+
'<%= command.id %> -X <stig-xccdf-xml> [-O <oval-xccdf-xml] [-o <output-folder>] [-m <metadata-json>] ' +
17+
'[-T (rule|group|cis|version)] [-s] [-L (info|warn|debug|verbose)] [-h] [--interactive]'
1818

1919
static readonly description =
2020
'Generate a new skeleton profile based on a XCCDF benchmark file'
2121

2222
static readonly examples = [
2323
{
24-
description: '\x1B[93mRequired flag only\x1B[0m',
25-
command: '<%= config.bin %> <%= command.id %> -i ./U_RHEL_6_STIG_V2R2_Manual-xccdf.xml',
24+
description: '\x1B[93mBase Command\x1B[0m',
25+
command: '<%= config.bin %> <%= command.id %> -X ./U_RHEL_6_STIG_V2R2_Manual-xccdf.xml',
2626
},
2727
{
2828
description: '\x1B[93mSpecifying OVAL and Output location\x1B[0m',
29-
command: '<%= config.bin %> <%= command.id %> -i ./U_RHEL_9_STIG_V1R2_Manual-xccdf.xml -O ./RHEL_9_Benchmark-oval.xml -o ./output/directory',
29+
command: '<%= config.bin %> <%= command.id %> -X ./U_RHEL_9_STIG_V1R2_Manual-xccdf.xml -O ./RHEL_9_Benchmark-oval.xml -o ./output/directory',
3030
},
3131
]
3232

src/commands/supplement/passthrough/read.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default class ReadPassthrough extends BaseCommand<typeof ReadPassthrough>
1111
static readonly examples = ['<%= config.bin %> <%= command.id %> -i hdf.json -o passthrough.json']
1212

1313
static readonly flags = {
14-
help: Flags.help({char: 'h'}),
1514
input: Flags.string({char: 'i', required: true, description: 'An input HDF file'}),
1615
output: Flags.string({char: 'o', description: 'An output `passthrough` JSON file (otherwise the data is sent to stdout)'}),
1716
}

src/commands/supplement/passthrough/write.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default class WritePassthrough extends BaseCommand<typeof WritePassthroug
2222
]
2323

2424
static readonly flags = {
25-
help: Flags.help({char: 'h'}),
2625
input: Flags.string({char: 'i', required: true, description: 'An input Heimdall Data Format file'}),
2726
passthroughFile: Flags.string({char: 'f', exclusive: ['passthroughData'], description: 'An input passthrough-data file (can contain any valid JSON); this flag or `passthroughData` must be provided'}),
2827
passthroughData: Flags.string({char: 'd', exclusive: ['passthroughFile'], description: 'Input passthrough-data (can be any valid JSON); this flag or `passthroughFile` must be provided'}),

src/commands/supplement/target/read.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default class ReadTarget extends BaseCommand<typeof ReadTarget> {
1111
static readonly examples = ['<%= config.bin %> <%= command.id %> -i hdf.json -o target.json']
1212

1313
static readonly flags = {
14-
help: Flags.help({char: 'h'}),
1514
input: Flags.string({char: 'i', required: true, description: 'An input HDF file'}),
1615
output: Flags.string({char: 'o', description: 'An output `target` JSON file (otherwise the data is sent to stdout)'}),
1716
}

src/commands/supplement/target/write.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default class WriteTarget extends BaseCommand<typeof WriteTarget> {
2222
]
2323

2424
static readonly flags = {
25-
help: Flags.help({char: 'h'}),
2625
input: Flags.string({char: 'i', required: true, description: 'An input Heimdall Data Format file'}),
2726
targetFile: Flags.string({char: 'f', exclusive: ['targetData'], description: 'An input target-data file (can contain any valid JSON); this flag or `targetData` must be provided'}),
2827
targetData: Flags.string({char: 'd', exclusive: ['targetFile'], description: 'Input target-data (can be any valid JSON); this flag or `targetFile` must be provided'}),

src/utils/oclif/baseCommand.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import {Args, Command, Flags, Interfaces} from '@oclif/core'
33
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>
44
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>
55

6+
export abstract class HelpBaseCommand extends Command {
7+
static readonly baseFlags = {
8+
help: Flags.help({
9+
char: 'h',
10+
aliases: ['explain', 'tell-me-more'],
11+
// Show this flag under a separate GLOBAL section in help.
12+
helpGroup: 'GLOBAL',
13+
description: 'Show CLI help',
14+
}),
15+
};
16+
}
617
export abstract class InteractiveBaseCommand extends Command {
718
static readonly baseFlags = {
819
interactive: Flags.boolean({
@@ -17,6 +28,7 @@ export abstract class InteractiveBaseCommand extends Command {
1728
export abstract class BaseCommand<T extends typeof Command> extends Command {
1829
// define flags that can be inherited by any command that extends BaseCommand
1930
static readonly baseFlags = {
31+
...HelpBaseCommand.baseFlags,
2032
...InteractiveBaseCommand.baseFlags,
2133
logLevel: Flags.option({
2234
char: 'L',
@@ -47,7 +59,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
4759
// If error message is for missing flags, display what fields
4860
// are required, otherwise show the error
4961
if (err.message.includes('See more help with --help')) {
50-
this.warn(err.message.replace('--help', '\x1B[93m<cli-command> -h or --help\x1B[0m'))
62+
this.warn(err.message.replace('--help', `\x1B[93m${process.argv.at(-2)} ${process.argv.at(-1)} -h or --help\x1B[0m`))
5163
} else {
5264
this.warn(err)
5365
}

0 commit comments

Comments
 (0)