Stream: beginners

Topic: Use Arg for a CLI program


view this post on Zulip Karakatiza (Dec 16 2023 at 17:49):

Hi all! Is there a way to use Arg module from basic-cli to create a simple command parser? I understand it is broken right now? https://github.com/roc-lang/roc/issues/5701

view this post on Zulip Luke Boswell (Dec 16 2023 at 18:02):

The task example uses Arg. Maybe you could do something similar?

readArgs : Task { url: Str, outputPath: Path } [FailedToReadArgs]_
readArgs =
    args <- Arg.list |> Task.attempt

    when args is
        Ok ([ _, first, second, .. ]) ->
            Task.ok { url: first, outputPath: Path.fromStr second }
        _ ->
            Task.err FailedToReadArgs

view this post on Zulip Karakatiza (Dec 16 2023 at 18:07):

A simple pattern matching, then. Hope it will cover my needs, thanks!


Last updated: Jul 05 2025 at 12:14 UTC