effect icon indicating copy to clipboard operation
effect copied to clipboard

CLI: Transform JS object of CLI options to a string

Open strogonoff opened this issue 1 year ago • 1 comments

What is the problem this feature would solve?

  • I made a script with effect-cli and I want to run it programmatically for any reason.

    Maybe I want to delegate logic dynamically based on a flag, but am limited to a bundler that cannot handle dynamic import()s properly, so have to resort to execSync() or the like.

  • I can create an option spec for some third-party script and avoid crafting strings.

What is the feature you are proposing to solve the problem?

A way to convert an option spec to a string with flags.

What alternatives have you considered?

Crafting strings works (but is error-prone).

strogonoff avatar Feb 10 '24 05:02 strogonoff

@strogonoff - I'm not sure I'm understanding properly.

Are you looking for a way to essentially get the usage statement for an option?

If so, you can already do that:

import { HelpDoc, Options, Usage } from "@effect/cli"

const fooOption = Options.text("foo")
const fooUsage = Options.getUsage(fooOption)
const renderedUsage = HelpDoc.toAnsiText(Usage.getHelp(fooUsage))

console.log(renderedUsage)
// --foo text

IMax153 avatar Feb 11 '24 14:02 IMax153

@strogonoff - I'm going to go ahead and close this issue as I think my answer might (?) cover your use case.

If not, please provide more details based on my questions I'll be happy to re-open!

IMax153 avatar Apr 19 '24 13:04 IMax153