{"version":3,"file":"completion.mjs","names":[],"sources":["../../src/extension/completion.ts"],"sourcesContent":["import type { ShellType } from '#src/util/shell-utils.ts';\nimport { resolveAllCommands } from '../core/commands.ts';\nimport type { AnyPadroneBuilder, CommandTypesBase, PadroneCommand } from '../types/index.ts';\nimport type { PadroneSchema } from '../types/schema.ts';\nimport type { WithCommand } from '../util/type-utils.ts';\nimport { getRootCommand } from '../util/utils.ts';\nimport { passthroughSchema } from './utils.ts';\n\n// ── Types ────────────────────────────────────────────────────────────────\n\ntype CompletionArgs = { shell?: string; setup?: boolean };\n\ntype CompletionCommand = PadroneCommand<'completion', '', PadroneSchema<CompletionArgs>, string, [], [], true>;\n\nexport type WithCompletion<T> = WithCommand<T, 'completion', CompletionCommand>;\n\n// ── Extension ────────────────────────────────────────────────────────────\n\n/**\n * Extension that adds the `completion` command for shell completion script generation.\n *\n * Usage:\n * ```ts\n * import { createPadrone } from 'padrone';\n * import { padroneCompletion } from 'padrone/completion';\n *\n * createPadrone('my-cli').extend(padroneCompletion())\n * ```\n */\nexport function padroneCompletion(): <T extends CommandTypesBase>(builder: T) => WithCompletion<T> {\n  return ((builder: AnyPadroneBuilder) =>\n    builder.command('completion', (c) =>\n      c\n        .configure({ description: 'Generate shell completion scripts', hidden: true })\n        .arguments(passthroughSchema({ shell: 'string', setup: 'boolean' }), { positional: ['shell'] })\n        .async()\n        .action(async (args, ctx) => {\n          const rootCommand = getRootCommand(ctx.command);\n          resolveAllCommands(rootCommand);\n          const { detectShell, generateCompletionOutput, setupCompletions } = await import('../feature/completion.ts');\n          const shell = args.shell as ShellType;\n          const setup = args.setup;\n          if (setup) {\n            const resolvedShell = shell ?? (await detectShell());\n            if (!resolvedShell) throw new Error('Could not detect shell. Specify one: completion bash --setup');\n            const setupResult = await setupCompletions(rootCommand.name, resolvedShell);\n            return `${setupResult.updated ? 'Updated' : 'Added'} ${rootCommand.name} completions in ${setupResult.file}`;\n          }\n          return generateCompletionOutput(rootCommand, shell);\n        }),\n    )) as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,SAAgB,oBAAmF;CACjG,SAAS,YACP,QAAQ,QAAQ,eAAe,MAC7B,EACG,UAAU;EAAE,aAAa;EAAqC,QAAQ;CAAK,CAAC,CAAC,CAC7E,UAAU,kBAAkB;EAAE,OAAO;EAAU,OAAO;CAAU,CAAC,GAAG,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAC9F,MAAM,CAAC,CACP,OAAO,OAAO,MAAM,QAAQ;EAC3B,MAAM,cAAc,eAAe,IAAI,OAAO;EAC9C,mBAAmB,WAAW;EAC9B,MAAM,EAAE,aAAa,0BAA0B,qBAAqB,MAAM,OAAO;EACjF,MAAM,QAAQ,KAAK;EAEnB,IADc,KAAK,OACR;GACT,MAAM,gBAAgB,SAAU,MAAM,YAAY;GAClD,IAAI,CAAC,eAAe,MAAM,IAAI,MAAM,8DAA8D;GAClG,MAAM,cAAc,MAAM,iBAAiB,YAAY,MAAM,aAAa;GAC1E,OAAO,GAAG,YAAY,UAAU,YAAY,QAAQ,GAAG,YAAY,KAAK,kBAAkB,YAAY;EACxG;EACA,OAAO,yBAAyB,aAAa,KAAK;CACpD,CAAC,CACL;AACJ"}