diff --git a/src/commands/git/branch.ts b/src/commands/git/branch.ts index 96b6052..188d7c2 100644 --- a/src/commands/git/branch.ts +++ b/src/commands/git/branch.ts @@ -4,7 +4,8 @@ import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import { Repository } from '../../git/models/repository'; import type { QuickPickItemOfT } from '../../quickpicks/items/common'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { @@ -343,13 +344,13 @@ export class BranchGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will create a new branch named ${state.name} from ${GitReference.toString( state.reference, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--switch'], { + createFlagsQuickPickItem(state.flags, ['--switch'], { label: `${context.title} and Switch`, description: '--switch', detail: `Will create and switch to a new branch named ${state.name} from ${GitReference.toString( @@ -416,14 +417,14 @@ export class BranchGitCommand extends QuickCommand { context: Context, ): StepResultGenerator { const confirmations: FlagsQuickPickItem[] = [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will delete ${GitReference.toString(state.references)}`, }), ]; if (!state.references.every(b => b.remote)) { confirmations.push( - FlagsQuickPickItem.create(state.flags, ['--force'], { + createFlagsQuickPickItem(state.flags, ['--force'], { label: `Force ${context.title}`, description: '--force', detail: `Will forcibly delete ${GitReference.toString(state.references)}`, @@ -432,7 +433,7 @@ export class BranchGitCommand extends QuickCommand { if (state.references.some(b => b.upstream != null)) { confirmations.push( - FlagsQuickPickItem.create(state.flags, ['--remotes'], { + createFlagsQuickPickItem(state.flags, ['--remotes'], { label: `${context.title} & Remote${ state.references.filter(b => !b.remote).length > 1 ? 's' : '' }`, @@ -441,7 +442,7 @@ export class BranchGitCommand extends QuickCommand { state.references, )} and any remote tracking branches`, }), - FlagsQuickPickItem.create(state.flags, ['--force', '--remotes'], { + createFlagsQuickPickItem(state.flags, ['--force', '--remotes'], { label: `Force ${context.title} & Remote${ state.references.filter(b => !b.remote).length > 1 ? 's' : '' }`, @@ -511,7 +512,7 @@ export class BranchGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, ['-m'], { + createFlagsQuickPickItem(state.flags, ['-m'], { label: context.title, detail: `Will rename ${GitReference.toString(state.reference)} to ${state.name}`, }), diff --git a/src/commands/git/cherry-pick.ts b/src/commands/git/cherry-pick.ts index d6cf299..f161bcd 100644 --- a/src/commands/git/cherry-pick.ts +++ b/src/commands/git/cherry-pick.ts @@ -3,7 +3,8 @@ import type { GitBranch } from '../../git/models/branch'; import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, @@ -213,20 +214,20 @@ export class CherryPickGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will apply ${GitReference.toString(state.references)} to ${GitReference.toString( context.destination, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--edit'], { + createFlagsQuickPickItem(state.flags, ['--edit'], { label: `${this.title} & Edit`, description: '--edit', detail: `Will edit and apply ${GitReference.toString(state.references)} to ${GitReference.toString( context.destination, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--no-commit'], { + createFlagsQuickPickItem(state.flags, ['--no-commit'], { label: `${this.title} without Committing`, description: '--no-commit', detail: `Will apply ${GitReference.toString(state.references)} to ${GitReference.toString( diff --git a/src/commands/git/fetch.ts b/src/commands/git/fetch.ts index dc27b65..eec6767 100644 --- a/src/commands/git/fetch.ts +++ b/src/commands/git/fetch.ts @@ -3,7 +3,8 @@ import type { Container } from '../../container'; import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { isStringArray } from '../../system/array'; import { fromNow } from '../../system/date'; import { pad } from '../../system/string'; @@ -143,7 +144,7 @@ export class FetchGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context, lastFetchedOn), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will fetch ${GitReference.toString(state.reference)}`, }), @@ -158,21 +159,21 @@ export class FetchGitCommand extends QuickCommand { step = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${this.title}`, state, context, lastFetchedOn), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will fetch ${reposToFetch}`, }), - FlagsQuickPickItem.create(state.flags, ['--prune'], { + createFlagsQuickPickItem(state.flags, ['--prune'], { label: `${this.title} & Prune`, description: '--prune', detail: `Will fetch and prune ${reposToFetch}`, }), - FlagsQuickPickItem.create(state.flags, ['--all'], { + createFlagsQuickPickItem(state.flags, ['--all'], { label: `${this.title} All`, description: '--all', detail: `Will fetch all remotes of ${reposToFetch}`, }), - FlagsQuickPickItem.create(state.flags, ['--all', '--prune'], { + createFlagsQuickPickItem(state.flags, ['--all', '--prune'], { label: `${this.title} All & Prune`, description: '--all --prune', detail: `Will fetch and prune all remotes of ${reposToFetch}`, diff --git a/src/commands/git/merge.ts b/src/commands/git/merge.ts index e3788d4..f19083d 100644 --- a/src/commands/git/merge.ts +++ b/src/commands/git/merge.ts @@ -4,7 +4,8 @@ import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { @@ -229,27 +230,27 @@ export class MergeGitCommand extends QuickCommand { const step: QuickPickStep> = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will merge ${pluralize('commit', count)} from ${GitReference.toString( state.reference, )} into ${GitReference.toString(context.destination)}`, }), - FlagsQuickPickItem.create(state.flags, ['--ff-only'], { + createFlagsQuickPickItem(state.flags, ['--ff-only'], { label: `Fast-forward ${this.title}`, description: '--ff-only', detail: `Will fast-forward merge ${pluralize('commit', count)} from ${GitReference.toString( state.reference, )} into ${GitReference.toString(context.destination)}`, }), - FlagsQuickPickItem.create(state.flags, ['--squash'], { + createFlagsQuickPickItem(state.flags, ['--squash'], { label: `Squash ${this.title}`, description: '--squash', detail: `Will squash ${pluralize('commit', count)} from ${GitReference.toString( state.reference, )} into one when merging into ${GitReference.toString(context.destination)}`, }), - FlagsQuickPickItem.create(state.flags, ['--no-ff'], { + createFlagsQuickPickItem(state.flags, ['--no-ff'], { label: `${this.title} without Fast-Forwarding`, description: '--no-ff', detail: `Will create a merge commit when merging ${pluralize( @@ -259,7 +260,7 @@ export class MergeGitCommand extends QuickCommand { context.destination, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--no-ff', '--no-commit'], { + createFlagsQuickPickItem(state.flags, ['--no-ff', '--no-commit'], { label: `${this.title} without Fast-Forwarding or Committing`, description: '--no-ff --no-commit', detail: `Will merge ${pluralize('commit', count)} from ${GitReference.toString( diff --git a/src/commands/git/pull.ts b/src/commands/git/pull.ts index 1b7494b..f59504d 100644 --- a/src/commands/git/pull.ts +++ b/src/commands/git/pull.ts @@ -5,7 +5,8 @@ import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { isStringArray } from '../../system/array'; import { fromNow } from '../../system/date'; import { pad, pluralize } from '../../system/string'; @@ -146,11 +147,11 @@ export class PullGitCommand extends QuickCommand { if (state.repos.length > 1) { step = this.createConfirmStep(appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will pull ${state.repos.length} repositories`, }), - FlagsQuickPickItem.create(state.flags, ['--rebase'], { + createFlagsQuickPickItem(state.flags, ['--rebase'], { label: `${this.title} with Rebase`, description: '--rebase', detail: `Will pull ${state.repos.length} repositories by rebasing`, @@ -181,7 +182,7 @@ export class PullGitCommand extends QuickCommand { ); } else { step = this.createConfirmStep(appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will pull${ branch.state.behind @@ -211,11 +212,11 @@ export class PullGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context, lastFetchedOn), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will pull${pullDetails}`, }), - FlagsQuickPickItem.create(state.flags, ['--rebase'], { + createFlagsQuickPickItem(state.flags, ['--rebase'], { label: `${this.title} with Rebase`, description: '--rebase', detail: `Will pull and rebase${pullDetails}`, diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 7aa5fb9..589e9ad 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -6,7 +6,8 @@ import type { GitBranchReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { isStringArray } from '../../system/array'; import { fromNow } from '../../system/date'; import { pad, pluralize } from '../../system/string'; @@ -163,11 +164,11 @@ export class PushGitCommand extends QuickCommand { if (state.repos.length > 1) { step = this.createConfirmStep(appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will push ${state.repos.length} repositories`, }), - FlagsQuickPickItem.create(state.flags, ['--force'], { + createFlagsQuickPickItem(state.flags, ['--force'], { label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`, description: `--force${useForceWithLease ? '-with-lease' : ''}`, detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${ @@ -196,7 +197,7 @@ export class PushGitCommand extends QuickCommand { if (branch != null && branch?.upstream == null) { for (const remote of await repo.getRemotes()) { items.push( - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, ['--set-upstream', remote.name, branch.name], { @@ -229,7 +230,7 @@ export class PushGitCommand extends QuickCommand { step = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, ['--force'], { + createFlagsQuickPickItem(state.flags, ['--force'], { label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`, description: `--force${useForceWithLease ? '-with-lease' : ''}`, detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${ @@ -252,7 +253,7 @@ export class PushGitCommand extends QuickCommand { ); } else if (branch != null && branch?.state.ahead > 0) { step = this.createConfirmStep(appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [branch.getRemoteName()!], { + createFlagsQuickPickItem(state.flags, [branch.getRemoteName()!], { label: this.title, detail: `Will push ${pluralize( 'commit', @@ -288,7 +289,7 @@ export class PushGitCommand extends QuickCommand { for (const remote of await repo.getRemotes()) { items.push( - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, ['--set-upstream', remote.name, status.branch], { @@ -358,12 +359,12 @@ export class PushGitCommand extends QuickCommand { ...(status?.state.behind ? [] : [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will push${pushDetails}`, }), ]), - FlagsQuickPickItem.create(state.flags, ['--force'], { + createFlagsQuickPickItem(state.flags, ['--force'], { label: `Force ${this.title}${useForceWithLease ? ' (with lease)' : ''}`, description: `--force${useForceWithLease ? '-with-lease' : ''}`, detail: `Will force push${useForceWithLease ? ' (with lease)' : ''} ${pushDetails}${ diff --git a/src/commands/git/rebase.ts b/src/commands/git/rebase.ts index aaf4534..5dddddb 100644 --- a/src/commands/git/rebase.ts +++ b/src/commands/git/rebase.ts @@ -4,7 +4,8 @@ import type { GitLog } from '../../git/models/log'; import { GitReference, GitRevision } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; import { Directive, DirectiveQuickPickItem } from '../../quickpicks/items/directive'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; import { getEditorCommand } from '../../system/utils'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; @@ -241,14 +242,14 @@ export class RebaseGitCommand extends QuickCommand { const step: QuickPickStep> = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will update ${GitReference.toString(context.destination)} by applying ${pluralize( 'commit', count, )} on top of ${GitReference.toString(state.reference)}`, }), - FlagsQuickPickItem.create(state.flags, ['--interactive'], { + createFlagsQuickPickItem(state.flags, ['--interactive'], { label: `Interactive ${this.title}`, description: '--interactive', detail: `Will interactively update ${GitReference.toString( diff --git a/src/commands/git/remote.ts b/src/commands/git/remote.ts index 0cff91a..19d60bb 100644 --- a/src/commands/git/remote.ts +++ b/src/commands/git/remote.ts @@ -7,7 +7,8 @@ import { Repository } from '../../git/models/repository'; import { Logger } from '../../logger'; import { showGenericErrorMessage } from '../../messages'; import type { QuickPickItemOfT } from '../../quickpicks/items/common'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { AsyncStepResultGenerator, @@ -332,11 +333,11 @@ export class RemoteGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will add remote '${state.name}' for ${state.url}`, }), - FlagsQuickPickItem.create(state.flags, ['-f'], { + createFlagsQuickPickItem(state.flags, ['-f'], { label: `${context.title} and Fetch`, description: '-f', detail: `Will add and fetch remote '${state.name}' for ${state.url}`, diff --git a/src/commands/git/reset.ts b/src/commands/git/reset.ts index ed62b80..f510cb9 100644 --- a/src/commands/git/reset.ts +++ b/src/commands/git/reset.ts @@ -4,7 +4,8 @@ import type { GitLog } from '../../git/models/log'; import type { GitRevisionReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, @@ -163,20 +164,20 @@ export class ResetGitCommand extends QuickCommand { const step: QuickPickStep> = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: this.title, detail: `Will reset (leaves changes in the working tree) ${GitReference.toString( context.destination, )} to ${GitReference.toString(state.reference)}`, }), - FlagsQuickPickItem.create(state.flags, ['--soft'], { + createFlagsQuickPickItem(state.flags, ['--soft'], { label: `Soft ${this.title}`, description: '--soft', detail: `Will soft reset (leaves changes in the index and working tree) ${GitReference.toString( context.destination, )} to ${GitReference.toString(state.reference)}`, }), - FlagsQuickPickItem.create(state.flags, ['--hard'], { + createFlagsQuickPickItem(state.flags, ['--hard'], { label: `Hard ${this.title}`, description: '--hard', detail: `Will hard reset (discards all changes) ${GitReference.toString( diff --git a/src/commands/git/revert.ts b/src/commands/git/revert.ts index 6c46757..34cf288 100644 --- a/src/commands/git/revert.ts +++ b/src/commands/git/revert.ts @@ -4,7 +4,8 @@ import type { GitLog } from '../../git/models/log'; import type { GitRevisionReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { PartialStepState, @@ -167,12 +168,12 @@ export class RevertGitCommand extends QuickCommand { const step: QuickPickStep> = this.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, ['--no-edit'], { + createFlagsQuickPickItem(state.flags, ['--no-edit'], { label: this.title, description: '--no-edit', detail: `Will revert ${GitReference.toString(state.references)}`, }), - FlagsQuickPickItem.create(state.flags, ['--edit'], { + createFlagsQuickPickItem(state.flags, ['--edit'], { label: `${this.title} & Edit`, description: '--edit', detail: `Will revert and edit ${GitReference.toString(state.references)}`, diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index 8353b37..55c587a 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -12,7 +12,8 @@ import type { Repository } from '../../git/models/repository'; import { Logger } from '../../logger'; import { showGenericErrorMessage } from '../../messages'; import type { QuickPickItemOfT } from '../../quickpicks/items/common'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { formatPath } from '../../system/formatPath'; import { pad } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; @@ -570,23 +571,23 @@ export class StashGitCommand extends QuickCommand { appendReposToTitle(`Confirm ${context.title}`, state, context), state.uris == null || state.uris.length === 0 ? [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: 'Will stash uncommitted changes', }), - FlagsQuickPickItem.create(state.flags, ['--include-untracked'], { + createFlagsQuickPickItem(state.flags, ['--include-untracked'], { label: `${context.title} & Include Untracked`, description: '--include-untracked', detail: 'Will stash uncommitted changes, including untracked files', }), - FlagsQuickPickItem.create(state.flags, ['--keep-index'], { + createFlagsQuickPickItem(state.flags, ['--keep-index'], { label: `${context.title} & Keep Staged`, description: '--keep-index', detail: 'Will stash uncommitted changes, but will keep staged files intact', }), ] : [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will stash changes from ${ state.uris.length === 1 @@ -594,7 +595,7 @@ export class StashGitCommand extends QuickCommand { : `${state.uris.length} files` }`, }), - FlagsQuickPickItem.create(state.flags, ['--keep-index'], { + createFlagsQuickPickItem(state.flags, ['--keep-index'], { label: `${context.title} & Keep Staged`, detail: `Will stash changes from ${ state.uris.length === 1 diff --git a/src/commands/git/tag.ts b/src/commands/git/tag.ts index 7d4aefa..cc748ae 100644 --- a/src/commands/git/tag.ts +++ b/src/commands/git/tag.ts @@ -5,7 +5,8 @@ import type { GitTagReference } from '../../git/models/reference'; import { GitReference } from '../../git/models/reference'; import type { Repository } from '../../git/models/repository'; import type { QuickPickItemOfT } from '../../quickpicks/items/common'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { pluralize } from '../../system/string'; import type { ViewsWithRepositoryFolders } from '../../views/viewBase'; import type { @@ -315,12 +316,12 @@ export class TagGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, state.message.length !== 0 ? ['-m'] : [], { + createFlagsQuickPickItem(state.flags, state.message.length !== 0 ? ['-m'] : [], { label: context.title, description: state.message.length !== 0 ? '-m' : '', detail: `Will create a new tag named ${state.name} at ${GitReference.toString(state.reference)}`, }), - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, state.message.length !== 0 ? ['--force', '-m'] : ['--force'], { diff --git a/src/commands/git/worktree.ts b/src/commands/git/worktree.ts index 6baf998..a8c9fae 100644 --- a/src/commands/git/worktree.ts +++ b/src/commands/git/worktree.ts @@ -18,7 +18,8 @@ import { showGenericErrorMessage } from '../../messages'; import type { QuickPickItemOfT } from '../../quickpicks/items/common'; import { QuickPickSeparator } from '../../quickpicks/items/common'; import { Directive } from '../../quickpicks/items/directive'; -import { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import type { FlagsQuickPickItem } from '../../quickpicks/items/flags'; +import { createFlagsQuickPickItem } from '../../quickpicks/items/flags'; import { basename, isDescendent } from '../../system/path'; import { pluralize, truncateLeft } from '../../system/string'; import { OpenWorkspaceLocation } from '../../system/utils'; @@ -596,7 +597,7 @@ export class WorktreeGitCommand extends QuickCommand { context, ), [ - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, [], { @@ -606,7 +607,7 @@ export class WorktreeGitCommand extends QuickCommand { }, recommendedRootUri, ), - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, ['-b'], { @@ -621,7 +622,7 @@ export class WorktreeGitCommand extends QuickCommand { ...(canCreateDirectlyInPicked ? [ QuickPickSeparator.create(), - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, ['--direct'], { @@ -631,7 +632,7 @@ export class WorktreeGitCommand extends QuickCommand { }, pickedUri, ), - FlagsQuickPickItem.create( + createFlagsQuickPickItem( state.flags, ['-b', '--direct'], { @@ -745,13 +746,13 @@ export class WorktreeGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will delete ${pluralize('worktree', state.uris.length, { only: state.uris.length === 1, })}${state.uris.length === 1 ? ` in $(folder) ${GitWorktree.getFriendlyPath(state.uris[0])}` : ''}`, }), - FlagsQuickPickItem.create(state.flags, ['--force'], { + createFlagsQuickPickItem(state.flags, ['--force'], { label: `Force ${context.title}`, description: 'including ANY UNCOMMITTED changes', detail: `Will forcibly delete ${pluralize('worktree', state.uris.length, { @@ -816,19 +817,19 @@ export class WorktreeGitCommand extends QuickCommand { const step: QuickPickStep> = QuickCommand.createConfirmStep( appendReposToTitle(`Confirm ${context.title}`, state, context), [ - FlagsQuickPickItem.create(state.flags, [], { + createFlagsQuickPickItem(state.flags, [], { label: context.title, detail: `Will open, in the current window, the worktree in $(folder) ${GitWorktree.getFriendlyPath( state.uri, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--new-window'], { + createFlagsQuickPickItem(state.flags, ['--new-window'], { label: `${context.title} in a New Window`, detail: `Will open, in a new window, the worktree in $(folder) ${GitWorktree.getFriendlyPath( state.uri, )}`, }), - FlagsQuickPickItem.create(state.flags, ['--reveal-explorer'], { + createFlagsQuickPickItem(state.flags, ['--reveal-explorer'], { label: `Reveal in File Explorer`, detail: `Will open, in the File Explorer, the worktree in $(folder) ${GitWorktree.getFriendlyPath( state.uri, diff --git a/src/quickpicks/items/flags.ts b/src/quickpicks/items/flags.ts index 857ee2e..4b3943e 100644 --- a/src/quickpicks/items/flags.ts +++ b/src/quickpicks/items/flags.ts @@ -4,18 +4,23 @@ import type { QuickPickItemOfT } from './common'; export type FlagsQuickPickItem = Context extends void ? QuickPickItemOfT : QuickPickItemOfT & { context: Context }; -export namespace FlagsQuickPickItem { - export function create(flags: T[], item: T[], options: QuickPickItem): FlagsQuickPickItem; - export function create( - flags: T[], - item: T[], - options: QuickPickItem, - context: Context, - ): FlagsQuickPickItem; - export function create(flags: T[], item: T[], options: QuickPickItem, context?: Context): any { - return { ...options, item: item, picked: hasFlags(flags, item), context: context }; - } + +export function createFlagsQuickPickItem(flags: T[], item: T[], options: QuickPickItem): FlagsQuickPickItem; +export function createFlagsQuickPickItem( + flags: T[], + item: T[], + options: QuickPickItem, + context: Context, +): FlagsQuickPickItem; +export function createFlagsQuickPickItem( + flags: T[], + item: T[], + options: QuickPickItem, + context?: Context, +): any { + return { ...options, item: item, picked: hasFlags(flags, item), context: context }; } + function hasFlags(flags: T[], has?: T | T[]): boolean { if (has === undefined) { return flags.length === 0;