pub struct DefaultAppPolicy<'a, I> { /* private fields */ }

Implementations§

Examples found in repository?
src/lib.rs (line 262)
261
262
263
264
265
266
267
268
269
    pub fn display(&mut self, show_global: bool) -> Result<()> {
        let policy = DefaultAppPolicy::new(vec![], show_global);
        let help = policy.format(self).ok_or_else(|| {
            Error::raise("Can not format app help with DefaultAppPolicy".to_string())
        })?;

        write!(&mut self.writer, "{}", help)
            .map_err(|e| Error::raise(format!("Can not write to handler: {:?}", e)))
    }
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()
    }
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())
    }
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())
    }
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())
    }

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.