Hello all! I'm trying to write a small CLI tool in Roc. Using basic-cli.
I'm looking at the docs and am missing anything about Opt or Param, or even SubCmd.
Is that a documentation bug, or a me-problem? Is my best option to read the library source code for now?
What is Opt, Param or SubCmd?
I'm not familiar with these names
I'm guessing this is an Elm thing... but its been so long I've fogotten
I can see those names in this directory of basic-cli
https://github.com/roc-lang/basic-cli/tree/main/platform/Arg
Ahk... right
I guess they're just undocumented as you say Martin
I think this is the bug I was talking about earlier today https://roc.zulipchat.com/#narrow/stream/306878-off-topic/topic/POC.3A.20AI.20agent.20writing.20Roc/near/474144956
ah, interesting
Is that a documentation bug, or a me-problem? Is my best option to read the library source code for now?
Yeah, I think it's a bug in roc docs generation... so best to read the source for now.
Checkout https://github.com/smores56/weaver
Docs here https://smores56.github.io/weaver/Opt/
The implementation in basic-cli was copied from weaver...
I think the plan is to use weaver instead of having it in the platform long term
Thank you both!
Martin Janiczek has marked this topic as resolved.
Actually, maybe one more question. Is there a pattern for non-empty list in either basic-cli or weaver? I ended up using Opt.strList
and a followup custom logic:
when Cli.parseOrDisplayMessage cli args is
Ok input ->
if List.isEmpty input.versions then
Stderr.line! "No versions to benchmark"
Task.err (Exit 1 "")
else
Bench.run input
Err message ->
Stderr.line! message
Task.err (Exit 1 "")
I guess if there's no Opt.nonemptyStrList
my best option is to extract the above length check into some validateInput
function that I use with Result.try
?
as in, when args |> Cli.parseOrDisplayMessage cli |> Result.try validateInput is ...
@Martin Janiczek I'd say you have a couple options:
First is to ask for two fields, the first being a single value and the second being a list:
cliParser =
{ Cli.weave <-
file: Param.str { name: "file", help: "The file to process." },
files: Param.strList { name: "files", help: "The rest of the files." },
}
parsed = parseArgsWith! cliParser args
allFiles = List.concat [file] files
Second is to validate the list value, which still requires post-parsing handling:
cliParser =
{ Cli.weave <-
# other fields...
files: Param.strList { name: "files" }
|> Cli.map \fs -> if List.isEmpty fs then Err EmptyFiles else Ok fs
}
parsed = parseArgsWith! cliParser args
files = parsed.files?
Last updated: Jul 06 2025 at 12:14 UTC