-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from TTRPG-Dev/qmalcolm--add-cli-show-function…
…ality Add CLI `show` command and subcommands
- Loading branch information
Showing
6 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
defmodule ExTTRPGDev.CLI do | ||
alias ExTTRPGDev.Dice | ||
alias ExTTRPGDev.RuleSystems | ||
alias ExTTRPGDev.RuleSystems.Abilities | ||
alias ExTTRPGDev.RuleSystems.Languages | ||
alias ExTTRPGDev.RuleSystems.Skills | ||
|
||
@moduledoc """ | ||
The CLI for the project | ||
|
@@ -12,7 +15,7 @@ defmodule ExTTRPGDev.CLI do | |
Optimus.new!( | ||
name: "ex_ttrpg_dev", | ||
description: "CLI for all things RPG", | ||
version: "0.2.0", | ||
version: "0.3.0", | ||
author: "Quigley Malcolm [email protected]", | ||
about: "Utility for playing tabletop role-playing games.", | ||
allow_unknown_args: false, | ||
|
@@ -39,18 +42,6 @@ defmodule ExTTRPGDev.CLI do | |
name: "system", | ||
about: "Top level command fo systems", | ||
subcommands: [ | ||
metadata: [ | ||
name: "metadata", | ||
about: "Show system metadata", | ||
args: [ | ||
system: [ | ||
value_name: "SYSTEM", | ||
help: "A supported system, e.g. dnd5e", | ||
required: true, | ||
parser: :string | ||
] | ||
] | ||
], | ||
gen: [ | ||
name: "gen", | ||
about: "Used for generating things for the system", | ||
|
@@ -68,6 +59,60 @@ defmodule ExTTRPGDev.CLI do | |
] | ||
] | ||
] | ||
], | ||
show: [ | ||
name: "show", | ||
about: "Used for showing information about the rule system", | ||
subcommands: [ | ||
abilities: [ | ||
name: "abilities", | ||
about: "Show the rule systems character abilities", | ||
args: [ | ||
system: [ | ||
value_name: "SYSTEM", | ||
help: "A supported system, e.g. dnd5e", | ||
required: true, | ||
parser: :string | ||
] | ||
] | ||
], | ||
languages: [ | ||
name: "languages", | ||
about: "Show the rule systems languages", | ||
args: [ | ||
system: [ | ||
value_name: "SYSTEM", | ||
help: "A supported system, e.g. dnd5e", | ||
required: true, | ||
parser: :string | ||
] | ||
] | ||
], | ||
metadata: [ | ||
name: "metadata", | ||
about: "Show system metadata", | ||
args: [ | ||
system: [ | ||
value_name: "SYSTEM", | ||
help: "A supported system, e.g. dnd5e", | ||
required: true, | ||
parser: :string | ||
] | ||
] | ||
], | ||
skills: [ | ||
name: "skills", | ||
about: "Show rule system skills", | ||
args: [ | ||
system: [ | ||
value_name: "SYSTEM", | ||
help: "A supported system, e.g. dnd5e", | ||
required: true, | ||
parser: :string | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
|
@@ -113,12 +158,11 @@ defmodule ExTTRPGDev.CLI do | |
|> RuleSystems.load_system!() | ||
|
||
case command do | ||
:metadata -> | ||
Map.get(loaded_system, :metadata) | ||
|> IO.inspect() | ||
|
||
:gen -> | ||
handle_system_generation_subcommands(subcommands, loaded_system) | ||
|
||
:show -> | ||
handle_system_show_subcommands(subcommands, loaded_system) | ||
end | ||
end | ||
|
||
|
@@ -132,4 +176,45 @@ defmodule ExTTRPGDev.CLI do | |
|> IO.inspect() | ||
end | ||
end | ||
|
||
def handle_system_show_subcommands( | ||
[command | _subcommands], | ||
%RuleSystems.RuleSystem{} = system | ||
) do | ||
case command do | ||
:abilities -> | ||
show_abilities(system) | ||
|
||
:languages -> | ||
show_languages(system) | ||
|
||
:metadata -> | ||
Map.get(system, :metadata) | ||
|> IO.inspect() | ||
|
||
:skills -> | ||
show_skills(system) | ||
end | ||
end | ||
|
||
def show_abilities(%RuleSystems.RuleSystem{abilities: %Abilities{specs: specs}}) do | ||
Enum.each(specs, fn %Abilities.Spec{name: name, abbreviation: abbr} -> | ||
IO.puts("(#{abbr}) #{name}") | ||
end) | ||
end | ||
|
||
def show_languages(%RuleSystems.RuleSystem{languages: languages}) do | ||
Enum.each(languages, fn %Languages.Language{name: name, script: script} -> | ||
IO.puts("Name: #{name}, Script: #{script}") | ||
end) | ||
end | ||
|
||
def show_skills(%RuleSystems.RuleSystem{skills: skills} = system) do | ||
Enum.each(skills, fn %Skills.Skill{name: name, modifying_stat: mod_stat} -> | ||
%Abilities.Spec{abbreviation: abbr} = | ||
RuleSystems.RuleSystem.get_spec_by_name(system, mod_stat) | ||
|
||
IO.puts("(#{abbr}) #{name}") | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters