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())
        })?;

        writeln!(&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 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()
    }
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())
    }
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())
    }
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())
    }

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.