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

Implementations§

Examples found in repository?
src/lib.rs (line 291)
283
284
285
286
287
288
289
290
291
292
293
294
295
296
    pub fn display_cmd<S>(&mut self, cmd: S) -> Result<()>
    where
        S: Into<Cow<'a, str>>,
    {
        let name = cmd.into();
        let cmd = self.cmds.iter().find(|v| v.name() == name).ok_or_else(|| {
            Error::raise(format!("Can not format help of {name} with DefaultPolicy"))
        })?;
        let policy = DefaultPolicy::new(self.name(), self.style.clone(), vec![], true);
        let help = policy.format(cmd).ok_or_else(|| todo!())?;

        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 97)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    pub fn get_command_usage(&self, item: &Command<'a>) -> Cow<'a, str> {
        let mut usages = vec![];
        let mut args = vec![];
        let mut block_hint = vec![];

        for block in item.block() {
            let (mut block_usages, mut block_args) = self.get_block_usage(block, item);

            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 item.block() {
            if !block.is_empty() {
                let arg = block.hint();

                if !arg.is_empty() {
                    block_hint.push(arg);
                }
            }
        }

        let mut ret = String::from("Usage: ");
        let usage = usages.join(" ");
        let block_hint = block_hint.join(" ");
        let args = args.join(" ");

        if !self.name.is_empty() {
            ret += &self.name;
            ret += " ";
        }
        if !item.name().is_empty() {
            ret += &item.name();
            ret += " ";
        }
        if !usage.is_empty() {
            ret += &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 228)
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
    fn format(&self, item: &Command<'a>) -> Option<Cow<'a, str>> {
        let usage = self.get_command_usage(item);
        let mut blocks = vec![usage];
        let head = item.head();
        let foot = item.foot();
        let block_spacing = "\n".repeat(1 + self.style.block_spacing);

        if !head.is_empty() {
            blocks.push(head);
        }
        for block in item.block() {
            if !block.is_empty() {
                let help = self.get_block_help(block, item);

                if !help.is_empty() {
                    blocks.push(help);
                }
            }
        }
        if !foot.is_empty() {
            blocks.push(foot);
        }
        Some(blocks.join(&block_spacing).into())
    }
Examples found in repository?
src/format/policy.rs (line 239)
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
    fn format(&self, item: &Command<'a>) -> Option<Cow<'a, str>> {
        let usage = self.get_command_usage(item);
        let mut blocks = vec![usage];
        let head = item.head();
        let foot = item.foot();
        let block_spacing = "\n".repeat(1 + self.style.block_spacing);

        if !head.is_empty() {
            blocks.push(head);
        }
        for block in item.block() {
            if !block.is_empty() {
                let help = self.get_block_help(block, item);

                if !help.is_empty() {
                    blocks.push(help);
                }
            }
        }
        if !foot.is_empty() {
            blocks.push(foot);
        }
        Some(blocks.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.