Skip to content

Commit

Permalink
Update ex_ttrpg_dev roll to handle multiple dice specs
Browse files Browse the repository at this point in the history
Previously, only one dice spec could be given, i.e. `ex_ttrpg_dev roll
3d4`. However, now multiple dice specs can be given in a single
invocation. That is, one can now do something like
```
$ ./ex_ttrpg_dev roll 10d10,10d12,10d20
10d10: [5, 3, 8, 4, 10, 3, 9, 2, 7, 4]
10d12: [9, 3, 3, 4, 11, 12, 12, 3, 6, 12]
10d20: [7, 3, 7, 4, 6, 1, 16, 3, 16, 6]
```
  • Loading branch information
QMalcolm committed Nov 22, 2024
1 parent 400f360 commit 87d7b34
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule ExTTRPGDev.CLI do
alias ExTTRPGDev.RuleSystems.Abilities
alias ExTTRPGDev.RuleSystems.Languages
alias ExTTRPGDev.RuleSystems.Skills
alias ExTTRPGDev.CustomParsers

@moduledoc """
The CLI for the project
Expand All @@ -30,7 +31,7 @@ defmodule ExTTRPGDev.CLI do
help:
"Dice in the format of xdy wherein x is the number of dice, y is the number of sides the dice should have",
required: true,
parser: :string
parser: &CustomParsers.dice_parser(&1)
]
]
],
Expand Down Expand Up @@ -144,9 +145,10 @@ defmodule ExTTRPGDev.CLI do
end
end

def handle_roll(%Optimus.ParseResult{args: %{dice: dice_str}}) do
Dice.roll(dice_str)
|> IO.inspect(label: "Results")
def handle_roll(%Optimus.ParseResult{args: %{dice: dice}}) do
dice
|> Enum.map(fn dice_spec -> {dice_spec, Dice.roll(dice_spec)} end)
|> Enum.each(fn {dice_spec, results} -> IO.inspect(results, label: dice_spec) end)
end

def handle_system_subcommands([command | subcommands], %Optimus.ParseResult{
Expand Down

0 comments on commit 87d7b34

Please sign in to comment.