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 323)
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
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() {
if !block.is_empty() {
let arg = block.hint();
if !arg.is_empty() {
block_hint.push(arg);
}
}
}
let mut ret = String::from("Usage: ");
// all the option usage
let global_usage = usages.join(" ");
let block_hint = block_hint.join(" ");
let command_usage = if app.has_cmd() { "<COMMAND>" } else { "" };
let args = args.join(" ");
if !global.name().is_empty() {
ret += &global.name();
ret += " ";
}
if !global_usage.is_empty() {
ret += &global_usage;
ret += " ";
}
if !command_usage.is_empty() {
ret += &command_usage;
ret += " ";
}
if self.hiding_pos {
if !block_hint.is_empty() {
ret += &block_hint;
ret += " ";
}
} else {
if !args.is_empty() {
ret += &args;
ret += " ";
}
}
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 545)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
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 559)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
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 567)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
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())
}