Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "4.5.5",
"version": "4.5.6-autocomplete.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type {
ArgDefinition,
ArgInput,
BooleanFlag,
Completion,
CustomOptions,
Deprecation,
Flag,
Expand Down
42 changes: 42 additions & 0 deletions src/interfaces/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ export type OptionFlagProps = FlagProps & {
* Should only be used on one flag at a time.
*/
allowStdin?: boolean | 'only'
/**
* Optional dynamic completion configuration.
* Provides intelligent autocomplete suggestions for flag values based on context.
* Requires autocomplete plugin to be installed.
*
* @example
* ```typescript
* completion: {
* options: async (ctx) => {
* return ['option1', 'option2', 'option3']
* }
* }
* ```
*/
completion?: Completion
}

export type FlagParserContext = Command & {token: FlagToken}
Expand Down Expand Up @@ -439,6 +454,33 @@ export type ParserInput = {
'--'?: boolean | undefined
}

/**
* Completion configuration for a flag
*/
export type Completion = {
/**
* Function that returns completion options
*
* @returns Promise resolving to array of completion strings
*
* @example
* ```typescript
* static flags = {
* 'target-org': Flags.string({
* description: 'Target org',
* completion: {
* options: async () => {
* const orgs = await getAuthenticatedOrgs()
* return orgs.map(o => o.alias)
* }
* }
* })
* }
* ```
*/
options(): Promise<string[]>
}

export type ParserContext = Command & {
token?: FlagToken | ArgToken | undefined
}
Expand Down
29 changes: 29 additions & 0 deletions test/interfaces/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {expect} from 'chai'

import * as Interfaces from '../../src/interfaces'

describe('Completion types', () => {
it('allows completion property on OptionFlag', () => {
const completion: Interfaces.Completion = {
async options() {
return ['option1', 'option2']
},
}

expect(completion).to.exist
expect(completion.options).to.be.a('function')
})

it('completion function returns promise of strings', async () => {
const completion: Interfaces.Completion = {
async options() {
return ['a', 'b', 'c']
},
}

const result = await completion.options()

expect(result).to.be.an('array')
expect(result).to.deep.equal(['a', 'b', 'c'])
})
})
Loading