Support custom type coertion
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Read the current type-coercion branch and Ruby's OptionParser#accept API first, then trace how parser definitions are registered and applied. Done means callers can register a custom User coercion alongside built-in types, parse the example input into a User, and retain existing required and pattern behavior.
Written by the indexing model from the issue text.
Description
Instead of an if/elsif/else expression, we can store accepted types in a hash and a proc that uses it to convert. That way, users can register custom type coercion strategies.
I'm thinking something like:
parser = ArgumentParser.build do
accept User do |string|
User.find(string)
end
required :action, pattern: [:delete, :update]
required :user, type: User
end
args = parser.parse!(["user-1"])
# => { user: #<User id="user-1"> }
We can copy OptionParser's API for that.
- Dominant language
- Ruby
- Stars
- 3
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from thoughtbot/argument_parser
-
good first issue
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in thoughtbot/argument_parser
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TheOdinProject/curriculum#31408 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
notch8/utk_knapsack#148 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Homebrew/homebrew-cask#288729 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100