<commit_before>// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{agent_error::ImlAgentError, lustre::lctl};
use combine::{stream::easy, EasyParser};
use iml_wire_types::snapshot::{Create, Destroy, List, Mount, Snapshot, Unmount};

mod parse;

pub async fn list(l: List) -> Result<Vec<Snapshot>, ImlAgentError> {
    let mut args = vec!["snapshot_list", "--fsname", &l.fsname];
    if let Some(name) = &l.name {
        args.push("--name");
        args.push(name);
    }
    if l.detail {
        args.push("--detail");
    }
    let stdout = lctl(args).await?;
    parse_snapshot_list(&stdout).map_err(ImlAgentError::CombineEasyError)
}

fn parse_snapshot_list(input: &str) -> Result<Vec<Snapshot>, easy::Errors<char, String, usize>> {<commit_msg>Ensure empty snapshots do not produce parse error (#2170)<commit_after>// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{agent_error::ImlAgentError, lustre::lctl};
use combine::{stream::easy, EasyParser};
use iml_wire_types::snapshot::{Create, Destroy, List, Mount, Snapshot, Unmount};

mod parse;

pub async fn list(l: List) -> Result<Vec<Snapshot>, ImlAgentError> {
    let mut args = vec!["snapshot_list", "--fsname", &l.fsname];
    if let Some(name) = &l.name {
        args.push("--name");
        args.push(name);
    }
    if l.detail {
        args.push("--detail");
    }
    let stdout = lctl(args).await?;
    let stdout = stdout.trim();

    if stdout.is_empty() {
        Ok(vec![])
    } else {
        parse_snapshot_list(&stdout).map_err(ImlAgentError::CombineEasyError)
    }
}

fn parse_snapshot_list(input: &str) -> Result<Vec<Snapshot>, easy::Errors<char, String, usize>> {
{'fraction_non_alphanumeric': 0.15491452991452992, 'fraction_numerical': 0.00641025641025641, 'mean_word_length': 3.7780612244897958, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6979120', 'n_tokens_mistral': 627, 'n_tokens_neox': 630, 'n_words': 165}