subshape icon indicating copy to clipboard operation
subshape copied to clipboard

CLI parser generation

Open harrysolovay opened this issue 1 year ago • 0 comments

Very rough idea / makes use of hypothetical $.exactUnion (#158) factory:

import * as $ from "scale"
import { parser } from "scale-cli-parser"

const $sync = $.variant(
  "sync",
  $.optionalField("config", $.str),
  $.optionalField("check", $.bool),
  $.exactUnion(
    $.variant("import-map", $.str),
    $.variant("package-json", $.str),
  ),
)

const $serve = $.variant(
  "serve",
  $.optionalField("port", $.str),
  $.optionalField("out", $.str),
)

export const parsed = parser($.exactUnion(
  $sync,
  $serve,
))(Deno.args)

if (parsed.sync) {
  // ...
} else if (parsed.serve) {
  // ...
}

For help text––depending on how doc-metadata attachment shapes up––we could do something like...

const $sync = $.variant(
  "sync",
  $.optionalField("config", $.str)
+   .docs("Path to your config file"),

harrysolovay avatar Apr 22 '23 17:04 harrysolovay