Struct aopt_help::prelude::DefaultAppPolicy
source · pub struct DefaultAppPolicy<'a, I> { /* private fields */ }
Implementations§
source§impl<'a, I> DefaultAppPolicy<'a, I>
impl<'a, I> DefaultAppPolicy<'a, I>
source§impl<'a, W: Write> DefaultAppPolicy<'a, AppHelp<'a, W>>
impl<'a, W: Write> DefaultAppPolicy<'a, AppHelp<'a, W>>
sourcepub fn get_block_usage(
&self,
item: &Block<'a, Cow<'a, str>>,
stores: &[Store<'a>]
) -> (Vec<String>, Vec<String>)
pub fn get_block_usage(
&self,
item: &Block<'a, Cow<'a, str>>,
stores: &[Store<'a>]
) -> (Vec<String>, Vec<String>)
Examples found in repository?
src/format/policy.rs (line 308)
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
pub fn get_app_usage(&self, app: &AppHelp<'a, W>) -> Cow<'a, str> {
let global = app.global();
let mut usages = vec![];
let mut args = vec![];
let mut block_hint = vec![];
for block in global.block() {
let (mut block_usages, mut block_args) = self.get_block_usage(block, global);
if !block_usages.is_empty() {
usages.append(&mut block_usages);
}
// if not omit args, using the args, otherwise using hint of block
if !block_args.is_empty() {
args.append(&mut block_args);
}
}
for block in global.block() {
let arg = block.hint();
if !arg.is_empty() {
block_hint.push(arg);
}
}
// all the option usage
let global_usage = usages.join(" ");
// all the args usage, hiding in default
let args = if self.hiding_pos {
"".to_owned()
} else {
args.join(" ")
};
let usage_space = if global_usage.is_empty() { "" } else { " " };
let block_hint = block_hint.join(" ");
let command_usage = if app.has_cmd() { "<COMMAND>" } else { "" };
let ret = if self.hiding_pos {
format!(
"Usage: {}{usage_space}{} {} {}",
global.name(),
global_usage,
command_usage,
block_hint
)
} else {
format!(
"Usage: {}{usage_space}{} {} {}",
global.name(),
global_usage,
command_usage,
args
)
};
ret.into()
}
sourcepub fn get_app_usage(&self, app: &AppHelp<'a, W>) -> Cow<'a, str>
pub fn get_app_usage(&self, app: &AppHelp<'a, W>) -> Cow<'a, str>
Examples found in repository?
src/format/policy.rs (line 519)
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
fn format(&self, app: &AppHelp<'a, W>) -> Option<Cow<'a, str>> {
let usage = self.get_app_usage(app);
let head = app.head();
let foot = app.foot();
let block_spacing = "\n".repeat(1 + app.style().block_spacing);
let mut usages = if usage.is_empty() {
vec![]
} else {
vec![usage]
};
if !head.is_empty() {
usages.push(head);
}
for block in app.block().iter() {
let block_help = self.get_block_help(block, app);
if !block_help.is_empty() {
usages.push(block_help);
}
}
if self.show_global {
for block in app.global().block() {
let global_help = self.get_global_help(block, app.global(), app);
if !global_help.is_empty() {
usages.push(global_help);
}
}
}
if !foot.is_empty() {
usages.push(foot);
}
Some(usages.join(&block_spacing).into())
}
sourcepub fn get_block_help(
&self,
block: &Block<'a, Cow<'a, str>>,
app: &AppHelp<'a, W>
) -> Cow<'a, str>
pub fn get_block_help(
&self,
block: &Block<'a, Cow<'a, str>>,
app: &AppHelp<'a, W>
) -> Cow<'a, str>
Examples found in repository?
src/format/policy.rs (line 533)
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
fn format(&self, app: &AppHelp<'a, W>) -> Option<Cow<'a, str>> {
let usage = self.get_app_usage(app);
let head = app.head();
let foot = app.foot();
let block_spacing = "\n".repeat(1 + app.style().block_spacing);
let mut usages = if usage.is_empty() {
vec![]
} else {
vec![usage]
};
if !head.is_empty() {
usages.push(head);
}
for block in app.block().iter() {
let block_help = self.get_block_help(block, app);
if !block_help.is_empty() {
usages.push(block_help);
}
}
if self.show_global {
for block in app.global().block() {
let global_help = self.get_global_help(block, app.global(), app);
if !global_help.is_empty() {
usages.push(global_help);
}
}
}
if !foot.is_empty() {
usages.push(foot);
}
Some(usages.join(&block_spacing).into())
}
sourcepub fn get_global_help(
&self,
item: &Block<'a, Cow<'a, str>>,
stores: &Vec<Store<'a>>,
app: &AppHelp<'a, W>
) -> Cow<'a, str>
pub fn get_global_help(
&self,
item: &Block<'a, Cow<'a, str>>,
stores: &Vec<Store<'a>>,
app: &AppHelp<'a, W>
) -> Cow<'a, str>
Examples found in repository?
src/format/policy.rs (line 541)
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
fn format(&self, app: &AppHelp<'a, W>) -> Option<Cow<'a, str>> {
let usage = self.get_app_usage(app);
let head = app.head();
let foot = app.foot();
let block_spacing = "\n".repeat(1 + app.style().block_spacing);
let mut usages = if usage.is_empty() {
vec![]
} else {
vec![usage]
};
if !head.is_empty() {
usages.push(head);
}
for block in app.block().iter() {
let block_help = self.get_block_help(block, app);
if !block_help.is_empty() {
usages.push(block_help);
}
}
if self.show_global {
for block in app.global().block() {
let global_help = self.get_global_help(block, app.global(), app);
if !global_help.is_empty() {
usages.push(global_help);
}
}
}
if !foot.is_empty() {
usages.push(foot);
}
Some(usages.join(&block_spacing).into())
}