Skip to content

Commit

Permalink
Merge branch 'main' into mdonnalley/support-deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 14, 2022
2 parents f6b7f7d + 63f3e0e commit 89a3169
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 15 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/notify-slack-on-pr-open.yml
@@ -0,0 +1,23 @@
name: Pull Request Slack Notification

on:
pull_request:
types: [opened, reopened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Notify Slack on PR open
env:
WEBHOOK_URL : ${{ secrets.CLI_TEAM_SLACK_WEBHOOK_URL }}
PULL_REQUEST_AUTHOR_ICON_URL : ${{ github.event.pull_request.user.avatar_url }}
PULL_REQUEST_AUTHOR_NAME : ${{ github.event.pull_request.user.login }}
PULL_REQUEST_AUTHOR_PROFILE_URL: ${{ github.event.pull_request.user.html_url }}
PULL_REQUEST_BASE_BRANCH_NAME : ${{ github.event.pull_request.base.ref }}
PULL_REQUEST_COMPARE_BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
PULL_REQUEST_NUMBER : ${{ github.event.pull_request.number }}
PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.name }}
PULL_REQUEST_TITLE : ${{ github.event.pull_request.title }}
PULL_REQUEST_URL : ${{ github.event.pull_request.html_url }}
uses: salesforcecli/github-workflows/.github/actions/prNotification@main
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "1.16.4",
"version": "1.16.7",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand Down Expand Up @@ -114,4 +114,4 @@
"pretest": "yarn build --noEmit && tsc -p test --noEmit --skipLibCheck"
},
"types": "lib/index.d.ts"
}
}
1 change: 1 addition & 0 deletions src/command.ts
Expand Up @@ -267,6 +267,7 @@ export default abstract class Command {
const opts = {context: this, ...options}
// the spread operator doesn't work with getters so we have to manually add it here
opts.flags = options?.flags
opts.args = options?.args
return Parser.parse(argv, opts)
}

Expand Down
2 changes: 2 additions & 0 deletions src/config/config.ts
Expand Up @@ -753,6 +753,7 @@ export async function toCached(c: Command.Class, plugin?: IPlugin): Promise<Comm
dependsOn: flag.dependsOn,
exclusive: flag.exclusive,
deprecated: flag.deprecated,
aliases: flag.aliases,
}
} else {
flags[name] = {
Expand All @@ -773,6 +774,7 @@ export async function toCached(c: Command.Class, plugin?: IPlugin): Promise<Comm
exclusive: flag.exclusive,
default: await defaultToCached(flag),
deprecated: flag.deprecated,
aliases: flag.aliases,
}
// a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
if (typeof flag.defaultHelp === 'function') {
Expand Down
12 changes: 5 additions & 7 deletions src/help/command.ts
Expand Up @@ -156,20 +156,18 @@ export class CommandHelp extends HelpFormatter {
const cmd = this.command

let description: string[] | undefined

if (this.opts.hideCommandSummaryInDescription) {
description = (cmd.description || '').split(POSSIBLE_LINE_FEED).slice(1)
} else if (cmd.description) {
description = [
...(cmd.summary || '').split(POSSIBLE_LINE_FEED),
const summary = cmd.summary ? `${cmd.summary}\n` : null
description = summary ? [
...summary.split(POSSIBLE_LINE_FEED),
...(cmd.description || '').split(POSSIBLE_LINE_FEED),
]
] : (cmd.description || '').split(POSSIBLE_LINE_FEED)
}

if (description) {
// Lines separated with only one newline or more than 2 can be hard to read in the terminal.
// Always separate by two newlines.
return this.wrap(compact(description).join('\n\n'))
return this.wrap(description.join('\n'))
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/parser.ts
Expand Up @@ -153,6 +153,10 @@ export type FlagProps = {
* Make the flag as deprecated.
*/
deprecated?: true | Deprecation;
/**
* Alternate names that can be used for this flag.
*/
aliases?: string[];
}

export type BooleanFlagProps = FlagProps & {
Expand Down
9 changes: 9 additions & 0 deletions src/parser/parse.ts
Expand Up @@ -39,6 +39,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
private readonly raw: ParsingToken[] = []

private readonly booleanFlags: { [k: string]: BooleanFlag<any> }
private readonly flagAliases: { [k: string]: BooleanFlag<any> | OptionFlag<any> }

private readonly context: any

Expand All @@ -52,6 +53,10 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
this.argv = [...input.argv]
this._setNames()
this.booleanFlags = pickBy(input.flags, f => f.type === 'boolean') as any
this.flagAliases = Object.fromEntries(Object.values(input.flags).flatMap(flag => {
return (flag.aliases ?? []).map(a => [a, flag])
}))

this.metaData = {}
}

Expand All @@ -64,6 +69,10 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
return name
}

if (this.flagAliases[name]) {
return this.flagAliases[name].name
}

if (arg.startsWith('--no-')) {
const flag = this.booleanFlags[arg.slice(5)]
if (flag && flag.allowNo) return flag.name
Expand Down
7 changes: 4 additions & 3 deletions test/help/format-command.test.ts
Expand Up @@ -25,6 +25,7 @@ describe('formatCommand', () => {
static aliases = ['app:init', 'create']

static description = `first line
multiline help`

static enableJsonFlag = true
Expand Down Expand Up @@ -222,7 +223,7 @@ DESCRIPTION
.commandHelp(class extends Command {
static id = 'apps:create'

static description = 'description of apps:create\nthese values are after and will show up in the command description'
static description = 'description of apps:create\n\nthese values are after and will show up in the command description'

static aliases = ['app:init', 'create']

Expand Down Expand Up @@ -259,7 +260,7 @@ ALIASES
.commandHelp(class extends Command {
static id = 'apps:create'

static description = 'root part of the description\nThe <%= config.bin %> CLI has <%= command.id %>'
static description = 'root part of the description\n\nThe <%= config.bin %> CLI has <%= command.id %>'

static disableJsonFlag = true
})
Expand All @@ -275,7 +276,7 @@ DESCRIPTION
.commandHelp(class extends Command {
static id = 'apps:create'

static description = 'root part of the description\r\nusing both carriage \nreturn and new line'
static description = 'root part of the description\r\n\nusing both carriage \n\nreturn and new line'

static disableJsonFlag = true
})
Expand Down
24 changes: 24 additions & 0 deletions test/parser/parse.test.ts
Expand Up @@ -1338,4 +1338,28 @@ See more help with --help`)
})
})
})

describe('flag aliases', () => {
it('works with defined name', async () => {
const out = await parse(['--foo'], {
flags: {
foo: flags.boolean({
aliases: ['bar'],
}),
},
})
expect(out.flags.foo).to.equal(true)
})

it('works with aliased name', async () => {
const out = await parse(['--bar'], {
flags: {
foo: flags.boolean({
aliases: ['bar'],
}),
},
})
expect(out.flags.foo).to.equal(true)
})
})
})
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -2460,9 +2460,9 @@ minimist-options@4.1.0:
kind-of "^6.0.3"

minimist@^1.2.3, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
version "1.2.7"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==

mocha@^8.4.0:
version "8.4.0"
Expand Down

0 comments on commit 89a3169

Please sign in to comment.