pub enum Grouping {
    Tag,
    Tree,
    None,
}

Variants§

§

Tag

§

Tree

§

None

Implementations§

Examples found in repository?
src/list/list_impl.rs (line 270)
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
pub async fn fmt_list<W: Write>(
    w: &mut W,
    script_repo: &mut ScriptRepo,
    opt: ListOptions,
) -> Result<()> {
    let latest_script_id = script_repo
        .latest_mut(1, Visibility::Normal)
        .map_or(-1, |s| s.id);

    let scripts_iter = do_list_query(script_repo, &opt.queries)
        .await?
        .into_iter()
        .map(|e| &*e.into_inner());
    let scripts_either = ScriptsEither::new(scripts_iter, opt.limit.map(|l| l.get()));
    let sorted = scripts_either.sorted();

    let final_table: Option<Table>;
    match opt.grouping {
        Grouping::None => {
            let mut opt = convert_opt(opt, Grid::new(scripts_either.len()));
            let scripts = scripts_either.collect();
            fmt_group(w, scripts, sorted, latest_script_id, &mut opt)?;
            final_table = extract_table(opt);
        }
        Grouping::Tree => {
            let mut opt = convert_opt(opt, &mut *w);
            let scripts = scripts_either.collect();
            tree::fmt(scripts, latest_script_id, &mut opt)?;
            final_table = extract_table(opt);
        }
        Grouping::Tag => {
            let mut opt = convert_opt(opt, Grid::new(scripts_either.len()));
            let mut script_map: HashMap<TagsKey, Vec<&ScriptInfo>> = HashMap::default();
            scripts_either.for_each(|script| {
                let key = TagsKey::new(script.tags.iter().cloned());
                let v = script_map.entry(key).or_default();
                v.push(script);
            });

            let mut scripts: Vec<_> = script_map.into_iter().collect();

            // NOTE: 以群組中執行次數的最大值排序, 無標籤永遠在上
            scripts.sort_by_key(|(k, v)| {
                if k.is_empty() {
                    None
                } else {
                    v.iter()
                        .map(|s| {
                            if s.exec_time.is_none() {
                                0
                            } else {
                                s.exec_count
                            }
                        })
                        .max()
                }
            });

            for (tags, scripts) in scripts.into_iter() {
                if !opt.grouping.is_none() {
                    let tags = tags.to_string();
                    let tags_width = tags.len();
                    let tags_txt = style(opt.plain, tags, |s| s.dimmed().italic());
                    match &mut opt.display_style {
                        DisplayStyle::Long(table) => {
                            table.add_row(vec![Cell::new_with_len(
                                tags_txt.to_string(),
                                tags_width,
                            )]);
                        }
                        DisplayStyle::Short(_, _) => {
                            writeln!(w, "{}", tags_txt)?;
                        }
                    }
                }
                fmt_group(w, scripts, sorted, latest_script_id, &mut opt)?;
            }
            final_table = extract_table(opt);
        }
    }
    if let Some(mut table) = final_table {
        write!(w, "{}", table.display())?;
        log::debug!("tree table: {:?}", table);
    }
    Ok(())
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. 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
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.