tjjfvi/subshape

CLI parser generation

harrysolovay opened this issue · 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"),