mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
Help+man+LibManual: Move argument handling to LibManual
This deduplicates argument handling logic from Help and man and makes it more modular for future use cases. The argument handling works as before: two arguments specify section and page (in this order), one argument specifies either a page (the first section that it's found in is used) or a path to a manpage markdown file.
This commit is contained in:
parent
64ca546a06
commit
b65258c093
9 changed files with 149 additions and 125 deletions
|
@ -13,6 +13,17 @@
|
|||
|
||||
namespace Manual {
|
||||
|
||||
ErrorOr<NonnullRefPtr<SectionNode>> SectionNode::try_create_from_number(StringView section)
|
||||
{
|
||||
auto maybe_section_number = section.to_uint<u32>();
|
||||
if (!maybe_section_number.has_value())
|
||||
return Error::from_string_literal("Section is not a number");
|
||||
auto section_number = maybe_section_number.release_value();
|
||||
if (section_number > number_of_sections)
|
||||
return Error::from_string_literal("Section number too large");
|
||||
return sections[section_number - 1];
|
||||
}
|
||||
|
||||
ErrorOr<String> SectionNode::path() const
|
||||
{
|
||||
return String::formatted("{}/{}{}", manual_base_path, top_level_section_prefix, m_section);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue