-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add value names for flags in md and man
- Loading branch information
1 parent
c4cb26c
commit cab0fb2
Showing
8 changed files
with
157 additions
and
60 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,61 @@ | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
|
||
use crate::Command; | ||
use roff::{bold, roman, Roff}; | ||
use crate::{Command, Flag, Value}; | ||
use roff::{bold, italic, roman, Roff}; | ||
|
||
pub fn render(c: &Command) -> String { | ||
let mut page = Roff::new(); | ||
page.control("TH", [&c.name.to_uppercase(), "1"]); | ||
page.control("SH", ["NAME"]); | ||
page.text([roman(&c.name)]); | ||
page.text([roman(c.name)]); | ||
page.control("SH", ["DESCRIPTION"]); | ||
page.text([roman(&c.summary)]); | ||
page.text([roman(c.summary)]); | ||
page.control("SH", ["OPTIONS"]); | ||
|
||
for arg in &c.args { | ||
page.control("TP", []); | ||
|
||
let mut flags = Vec::new(); | ||
for l in &arg.long { | ||
for Flag { flag, value } in &arg.long { | ||
if !flags.is_empty() { | ||
flags.push(roman(", ")); | ||
} | ||
flags.push(bold(format!("--{l}"))); | ||
flags.push(bold(format!("--{flag}"))); | ||
match value { | ||
Value::Required(name) => { | ||
flags.push(roman("=")); | ||
flags.push(italic(*name)); | ||
} | ||
Value::Optional(name) => { | ||
flags.push(roman("[")); | ||
flags.push(roman("=")); | ||
flags.push(italic(*name)); | ||
flags.push(roman("]")); | ||
} | ||
Value::No => {} | ||
} | ||
} | ||
for s in &arg.short { | ||
for Flag { flag, value } in &arg.short { | ||
if !flags.is_empty() { | ||
flags.push(roman(", ")); | ||
} | ||
flags.push(bold(format!("-{s}"))); | ||
flags.push(bold(format!("-{flag}"))); | ||
match value { | ||
Value::Required(name) => { | ||
flags.push(roman(" ")); | ||
flags.push(italic(*name)); | ||
} | ||
Value::Optional(name) => { | ||
flags.push(roman("[")); | ||
flags.push(italic(*name)); | ||
flags.push(roman("]")); | ||
} | ||
Value::No => {} | ||
} | ||
} | ||
page.text(flags); | ||
page.text([roman(&arg.help)]); | ||
page.text([roman(arg.help)]); | ||
} | ||
page.render() | ||
} |
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