citty icon indicating copy to clipboard operation
citty copied to clipboard

Support multiple optional positional args

Open Rigo-m opened this issue 2 years ago • 2 comments

Describe the feature

When using lint-staged, the default behaviour is to pass filenames as positional arguments to linting CLIs, e.g.: your-cmd file1.ext file2.ext

AFAIK there's no way to support positional arguments in this way in citty. So, if I want to be able to support multiple positional arguments in my Citty CLI commands, I can't do it right now (or, at least, it's unclear if there is a way to do so).

Additional information

  • [ ] Would you be willing to help implement this feature?

Rigo-m avatar Oct 06 '23 13:10 Rigo-m

Maybe this will be a decent idea, .or anybody has better advise :)

export default defineCommand({
  meta: {
    name: "lint",
    description: "A test command",
  },
  args: {
    files: {
      type: "multiple",
      description: "Files need be lint",
    },
  },
  run({ args }) {
	// lint fileA.ts fileB.ts
	console.log(args.files) //=> ['fileA.ts', 'fileB.ts]
  },
});

Additional information

  • [X] Would you be willing to help implement this feature?

peterroe avatar Oct 13 '23 09:10 peterroe

yep, variadic positional arguments would be helpful, maybe args._ just works?

Rettend avatar Sep 09 '24 16:09 Rettend