pace_rs/commands/settings/
set.rs1use abscissa_core::{Command, Runnable};
2use clap::{Parser, Subcommand};
3
4use pace_cli::prompt_time_zone;
5use pace_core::prelude::PaceConfig;
6
7use crate::prelude::PACE_APP;
8
9#[derive(Subcommand, Command, Debug, Runnable)]
11pub enum SetChoiceSubCmd {
12 #[clap(visible_alias = "tz")]
14 Timezone(SetTimezoneSubCmd),
15}
16
17#[derive(Command, Debug, Parser, Runnable)]
19pub struct SetChoiceCmd {
20 #[clap(subcommand)]
21 commands: SetChoiceSubCmd,
22}
23
24#[derive(Command, Debug, Parser)]
26pub struct SetTimezoneSubCmd {}
27
28impl Runnable for SetTimezoneSubCmd {
29 fn run(&self) {
30 let time_zone = prompt_time_zone().expect("Time zone not set.");
31
32 let mut config: PaceConfig = toml::from_str(
33 std::fs::read_to_string(PACE_APP.config_path())
34 .unwrap()
35 .as_str(),
36 )
37 .unwrap();
38
39 config.set_time_zone(time_zone);
40
41 std::fs::write(PACE_APP.config_path(), toml::to_string(&config).unwrap()).unwrap();
42 }
43}