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
|
use crate::{app::App, configuration::SettingsBuilder};
use anyhow::Result;
use clap::{Parser, ValueEnum};
#[derive(Parser)]
pub struct Args {
/// Reset the configuration to default
#[clap(long)]
reset: bool,
/// Show the configuration
#[clap(long)]
show: bool,
/// Set the keybindings mode
#[clap(long)]
mode: Option<Mode>,
/// Set the icons
#[clap(long)]
icons: Option<Icons>,
}
#[derive(Parser, Clone, Copy, ValueEnum)]
enum Icons {
/// Set the icons to special characters
Special,
/// Set the icons to char
Chars,
}
#[derive(Parser, Clone, Copy, ValueEnum)]
enum Mode {
/// Set the mode to vi
Vi,
/// Set the mode to normal
Normal,
}
pub fn run(mut app: App, args: Args) -> Result<()> {
let Args {
reset,
show,
mode,
icons,
} = args;
if reset {
let mut sb = SettingsBuilder::default();
sb.save_to_file()?;
app.settings = sb.build();
}
match mode {
Some(Mode::Vi) => app.settings.set_vi_mode(),
Some(Mode::Normal) => app.settings.set_normal_mode(),
None => {}
}
match icons {
Some(Icons::Special) => app.settings.set_special_icons(),
Some(Icons::Chars) => app.settings.set_char_icons(),
None => {}
}
if show {
println!("{}", serde_json::to_string_pretty(&app.settings)?);
}
Ok(())
}
|