Skip to content

Commit a6f2b34

Browse files
committed
Add switch --no-table-formatting to 'rush list'
1 parent fe4019a commit a6f2b34

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

apps/rush-lib/src/cli/actions/ListAction.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CommandLineFlagParameter } from '@rushstack/ts-command-line';
44
import { RushConfigurationProject } from '../../api/RushConfigurationProject';
55
import * as Table from 'cli-table';
66

7-
87
export interface IJsonEntry {
98
name: string;
109
version: string;
@@ -21,6 +20,7 @@ export class ListAction extends BaseRushAction {
2120
private _path: CommandLineFlagParameter;
2221
private _fullPath: CommandLineFlagParameter;
2322
private _jsonFlag: CommandLineFlagParameter;
23+
private _notTableFormatting: CommandLineFlagParameter;
2424

2525
public constructor(parser: RushCommandLineParser) {
2626
super({
@@ -63,6 +63,11 @@ export class ListAction extends BaseRushAction {
6363
parameterLongName: '--json',
6464
description: 'If this flag is specified, output will be in JSON format.'
6565
});
66+
67+
this._notTableFormatting = this.defineFlagParameter({
68+
parameterLongName: '--no-table-formatting',
69+
description: 'If this flag is specified, then the output table will not have headers or border characters making it easier to parse (for example, using grep).'
70+
});
6671
}
6772

6873
protected async run(): Promise<void> {
@@ -117,8 +122,16 @@ export class ListAction extends BaseRushAction {
117122
if (this._fullPath.value) {
118123
tableHeader.push('Full Path');
119124
}
125+
120126
const table: Table = new Table({
121-
head: tableHeader
127+
head: this._notTableFormatting.value ? [] : tableHeader,
128+
chars: this._notTableFormatting.value ? {
129+
'top': '', 'top-mid': '', 'top-left': '', 'top-right': '',
130+
'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': '',
131+
'left': '', 'left-mid': '', 'mid': '', 'mid-mid': '',
132+
'right': '', 'right-mid': '', 'middle': ' '
133+
} : {},
134+
style: this._notTableFormatting ? { 'padding-left': 0, 'padding-right': 0 } : {}
122135
});
123136

124137
allPackages.forEach((config: RushConfigurationProject, name: string) => {

apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,25 @@ Optional arguments:
362362
`;
363363
364364
exports[`CommandLineHelp prints the help for each action: list 1`] = `
365-
"usage: rush list [-h] [-v] [-p] [-f] [--json]
365+
"usage: rush list [-h] [-v] [-p] [-f] [--json] [--no-table-formatting]
366366
367367
List package names, and optionally version (--version) and path (--path) or
368368
full path (--full-path), for projects in the current rush config.
369369
370370
Optional arguments:
371-
-h, --help Show this help message and exit.
372-
-v, --version If this flag is specified, the project version will be
373-
displayed in a column along with the package name.
374-
-p, --path If this flag is specified, the project path will be
375-
displayed in a column along with the package name.
376-
-f, --full-path If this flag is specified, the project full path will be
377-
displayed in a column along with the package name.
378-
--json If this flag is specified, output will be in JSON format.
371+
-h, --help Show this help message and exit.
372+
-v, --version If this flag is specified, the project version will
373+
be displayed in a column along with the package name.
374+
-p, --path If this flag is specified, the project path will be
375+
displayed in a column along with the package name.
376+
-f, --full-path If this flag is specified, the project full path will
377+
be displayed in a column along with the package name.
378+
--json If this flag is specified, output will be in JSON
379+
format.
380+
--no-table-formatting
381+
If this flag is specified, then the output table will
382+
not have headers or border characters making it
383+
easier to parse.
379384
"
380385
`;
381386

0 commit comments

Comments
 (0)