arcanis / clipanion

Type-safe CLI library / framework with no runtime dependencies
https://mael.dev/clipanion/
1.1k stars 61 forks source link

Option.Rest() & Option.Proxy() can not be used together. #163

Open magicdawn opened 2 months ago

magicdawn commented 2 months ago
export class FooCommand extends Command {
  static paths = [['foo']]

  idList = Option.Rest({
    name: 'id list',
  })

  extraArgs = Option.Proxy()

  async execute() {
  }
}

when exec cli foo id1 id2 -- -p ALL error logs:

Error: Infinite lists cannot be declared multiple times in the same command
    at CommandBuilder.addRest (/tmp/demo/node_modules/.pnpm/clipanion@3.2.1_typanion@3.12.1/node_modules/clipanion/lib/core.js:564:19)
    at CommandBuilder.addProxy (/tmp/demo/node_modules/.pnpm/clipanion@3.2.1_typanion@3.12.1/node_modules/clipanion/lib/core.js:572:14)
    at definition (/tmp/demo/node_modules/.pnpm/clipanion@3.2.1_typanion@3.12.1/node_modules/clipanion/lib/advanced/options/Proxy.js:24:21)
    at Cli.register (/tmp/demo/node_modules/.pnpm/clipanion@3.2.1_typanion@3.12.1/node_modules/clipanion/lib/advanced/Cli.js:139:13)
    at <anonymous> (/tmp/demo/src/cli.ts:31:5)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

and I noticed that Option.Proxy() will consume all args after last path component.

It would be nice to support explicit proxied args, separated by --.

and In my case, assign components before -- to Option.Rest() [id1, id2], and after -p ALL to Option.Proxy(), so things like for(id of bvidList) exec(other-command ${id} ${extraArgs}) can be done.


Current if only use Option.Rest() with cli foo id1 id2 -- -p ALL, idList will be [ 'id1', 'id2', '-p', 'ALL' ], there is no clear remark to manual split them into [id1, id2] & [-p, ALL]

Thanks for your works anyway~