zx icon indicating copy to clipboard operation
zx copied to clipboard

Feature request: accept a minimist-like object of arguments in $`command`

Open pizzafroide opened this issue 2 years ago • 4 comments

Up to now, $`command ${arg}` processes:

  • arrays (by substituting and quoting each of its items, then joining them using space characters),
  • objects with a stdout property (by substituting them with the value of stdout, then quoting it),
  • and any other value is "stringified" and quoted.

It would be interesting to also have a special treatment for objects that don't have a stdout property and which don't override toString (as in o.toString !== Object.prototype.toString). This kind of objects could be seen as minimist-like objects, and would be substituted like so:

$`command ${{
  _: ['foo', 'bar'],
  a: true,
  bc: true,
  d: 'value',
  e: ['value1', 'value2'],
  '-f': 'value',
  '--': {
    g: true
  }
}}`
// $ command -a -bc --d value --e value1 --e value2 -f value foo bar -- -g

pizzafroide avatar Mar 01 '23 08:03 pizzafroide

Interesting idea. Let me think about it.

antonmedv avatar Mar 01 '23 11:03 antonmedv

Dropping this for inspiration purpose: https://github.com/lukeed/mri

Kikobeats avatar Mar 07 '23 15:03 Kikobeats

@antonmedv I would like to take this up looks interesting.

RavenColEvol avatar May 30 '23 18:05 RavenColEvol

I’m still not sure we need this.

antonmedv avatar Sep 13 '23 15:09 antonmedv