1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Defines supported transforms.
use std::{collections::HashMap, rc::Rc};
use ini_merge::mutations::transforms as ini_transforms;
use itertools::Itertools;
use strum::{EnumIter, EnumMessage, EnumString, IntoStaticStr};
/// Supported transforms
///
/// This serves as a central point for documentation, parsing, generating
/// lists etc.
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, EnumString, IntoStaticStr, EnumMessage)]
pub(crate) enum Transform {
/// Compare the value as an unsorted list.
/// Useful because Konversation likes to reorder lists.
///
/// Arguments:
/// * separator="," (Separating character between list elements)
#[strum(serialize = "unsorted-list")]
UnsortedLists,
/// Specialised transform to handle KDE changing certain global
/// shortcuts back and forth between formats like:
///
/// playmedia=none,,Play media playback
/// playmedia=none,none,Play media playback
///
/// No arguments.
#[strum(serialize = "kde-shortcut")]
KdeShortcut,
/// Get the value for a key from the system keyring. Useful for passwords
/// etc that you do not want in your dotfiles repo.
///
/// Arguments:
/// * service="service-name" (service name to find entry in the keyring)
/// * user="user-name" (user name to find entry in the keyring)
///
/// On Linux you can add an entry to the keyring using:
/// secret-tool store --label="Descriptive name" service "service-name" username "user-name"
#[strum(serialize = "keyring")]
Keyring,
}
impl Transform {
/// Print help for transforms
pub(crate) fn help() {
use strum::IntoEnumIterator;
let docs = Self::iter().map(|elem| {
let name: &str = elem.into();
format!(
"{}\n{}\n{}",
name,
"-".repeat(name.len()),
elem.get_documentation().unwrap_or("Missing docs")
)
});
println!("Supported transforms:");
println!("====================\n");
println!(
"{}",
Itertools::intersperse(docs, "\n\n".to_string()).collect::<String>()
);
}
/// Construct transform with arguments
pub(crate) fn construct(
self,
args: &HashMap<String, String>,
) -> anyhow::Result<Rc<dyn ini_transforms::Transformer>> {
use ini_transforms::Transformer;
match self {
Transform::UnsortedLists => Ok(Rc::new(
ini_transforms::TransformUnsortedLists::from_user_input(args)?,
)),
Transform::KdeShortcut => Ok(Rc::new(
ini_transforms::TransformKdeShortcut::from_user_input(args)?,
)),
#[cfg(feature = "keyring")]
Transform::Keyring => Ok(Rc::new(ini_transforms::TransformKeyring::from_user_input(
args,
)?)),
#[cfg(not(feature = "keyring"))]
Transform::Keyring => Err(anyhow::anyhow!(
"This build of chezmoi_modify_manager does not support the keyring transform"
)),
}
}
}