Skip to content
Discussion options

You must be logged in to vote

@eakl @rj-elias The nonEmpty() modifier has been implemented and can solve your use case. Here's how you can combine it with longestMatch() and withDefault():

import { longestMatch, object } from "@optique/core/constructs";
import { nonEmpty, optional, withDefault } from "@optique/core/modifiers";
import { constant, option } from "@optique/core/primitives";
import { string } from "@optique/core/valueparser";

// This parser requires at least one token to be consumed
const activeParser = nonEmpty(object({
  mode: constant("active" as const),
  cwd: withDefault(
    option("--cwd", string()),
    "./",
  ),
  key: optional(option("--key", string())),
}));

// Falls back to help mode when no…

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
3 replies
@eakl
Comment options

@dahlia
Comment options

@eakl
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by dahlia
Comment options

You must be logged in to vote
2 replies
@dahlia
Comment options

@dahlia
Comment options

Comment options

You must be logged in to vote
4 replies
@dahlia
Comment options

@rj-elias
Comment options

@dahlia
Comment options

@rj-elias
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants