-
Notifications
You must be signed in to change notification settings - Fork 657
[rush] Expose Rush Command Line Parser via API #4293
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
Merged
iclanton
merged 20 commits into
microsoft:main
from
william2958:will/expose-command-line
Feb 29, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d57f7aa
feat: set up basic test for RushCommandLine
william2958 f80c785
docs: add comments
william2958 d6dce7a
feat: rename to RushCommandLineAPI
william2958 3d6dca3
feat: add change file
william2958 7389f0d
chore: fix typo
william2958 3364ddf
chore: update docs
william2958 ec2297d
chore: update snapshot for rush-sdk
william2958 b9b9baf
feat: add requested changes
william2958 ed867df
Update libraries/rush-lib/src/api/test/RushCommandLine.test.ts
william2958 57057c2
Update libraries/rush-lib/src/api/RushCommandLine.ts
william2958 00bf622
Update common/changes/@microsoft/rush/will-expose-command-line_2023-0…
william2958 e74f788
feat: cache commandLineParser in RushCommandLine api
william2958 0d68fd9
chore: update rush lib api signature
william2958 10b6c92
PR Comments
william2958 6570894
chore: linting
william2958 00c3627
chore: docs
william2958 252be4c
chore: initialize workspace command line map
william2958 2b05e41
API and test improvements.
iclanton 9a51e3b
More API tweaks.
iclanton 59be5ce
Rush change.
iclanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@microsoft/rush/will-expose-command-line_2023-08-24-22-36.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@microsoft/rush", | ||
| "comment": "Introduce a `RushCommandLine` API that exposes an object representing the skeleton of the Rush command-line.", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/rush" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import { CommandLineParameterKind } from '@rushstack/ts-command-line'; | ||
|
|
||
| import { RushCommandLineParser } from '../cli/RushCommandLineParser'; | ||
|
|
||
| /** | ||
| * Information about the available parameters associated with a Rush action | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface IRushCommandLineParameter { | ||
| /** | ||
| * The corresponding string representation of CliParameterKind | ||
| */ | ||
| readonly kind: keyof typeof CommandLineParameterKind; | ||
|
|
||
| /** | ||
| * The long name of the flag including double dashes, e.g. "--do-something" | ||
| */ | ||
| readonly longName: string; | ||
|
|
||
| /** | ||
| * An optional short name for the flag including the dash, e.g. "-d" | ||
| */ | ||
| readonly shortName?: string; | ||
|
|
||
| /** | ||
| * Documentation for the parameter that will be shown when invoking the tool with "--help" | ||
| */ | ||
| readonly description: string; | ||
|
|
||
| /** | ||
| * If true, then an error occurs if the parameter was not included on the command-line. | ||
| */ | ||
| readonly required?: boolean; | ||
|
|
||
| /** | ||
| * If provided, this parameter can also be provided by an environment variable with the specified name. | ||
| */ | ||
| readonly environmentVariable?: string; | ||
| } | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The full spec of an available Rush command line action | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface IRushCommandLineAction { | ||
| actionName: string; | ||
| parameters: IRushCommandLineParameter[]; | ||
| } | ||
|
|
||
| /** | ||
| * The full spec of a Rush CLI | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface IRushCommandLineSpec { | ||
| actions: IRushCommandLineAction[]; | ||
| } | ||
|
|
||
| const _commandLineSpecByWorkspaceFolder: Map<string, IRushCommandLineSpec> = new Map(); | ||
|
|
||
| /** | ||
| * Information about the available CLI commands | ||
| * | ||
| * @beta | ||
| */ | ||
| export class RushCommandLine { | ||
| public static getCliSpec(rushJsonFolder: string): IRushCommandLineSpec { | ||
| let result: IRushCommandLineSpec | undefined = _commandLineSpecByWorkspaceFolder.get(rushJsonFolder); | ||
|
|
||
| if (!result) { | ||
| const commandLineParser: RushCommandLineParser = new RushCommandLineParser({ cwd: rushJsonFolder }); | ||
|
|
||
| // extract the set of command line elements from the command line parser | ||
| const actions: IRushCommandLineAction[] = []; | ||
| for (const { actionName, parameters: rawParameters } of commandLineParser.actions) { | ||
| const parameters: IRushCommandLineParameter[] = []; | ||
| for (const { | ||
| kind: rawKind, | ||
| longName, | ||
| shortName, | ||
| description, | ||
| required, | ||
| environmentVariable | ||
| } of rawParameters) { | ||
| parameters.push({ | ||
| kind: CommandLineParameterKind[rawKind] as keyof typeof CommandLineParameterKind, | ||
| longName, | ||
| shortName, | ||
| description, | ||
| required, | ||
| environmentVariable | ||
| }); | ||
| } | ||
|
|
||
| actions.push({ | ||
| actionName, | ||
| parameters | ||
| }); | ||
| } | ||
|
|
||
| result = { actions }; | ||
| _commandLineSpecByWorkspaceFolder.set(rushJsonFolder, result); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import path from 'node:path'; | ||
|
|
||
| import { RushCommandLine } from '../RushCommandLine'; | ||
|
|
||
| describe(RushCommandLine.name, () => { | ||
| it(`Returns a spec`, async () => { | ||
| const spec = RushCommandLine.getCliSpec(path.resolve(__dirname, '../../cli/test/repo/')); | ||
| expect(spec).toMatchSnapshot(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.