Skip to content

Create .toml configuration file for Purrgress #1

@fariosofernando

Description

@fariosofernando

Describe the feature:

Improve the backup schedule configuration by using a configuration file (.config.toml) for the user, instead of hard-coding the interval values ​​directly in the code. The idea is to allow the user to define the backup frequency in a more flexible way, by editing the configuration, and then the program can read this configuration to determine the time interval.

Tasks:

  1. Create a configuration file ~/.purrgres/.config.toml that contains the time settings.
  • Example structure:
[general]
backup_interval = "1day" # Can be "1day", "1month", "7days", etc.
  1. In the source code, modify the way to define the backup interval:
  • Currently, we have:
let schedule = utils::schedule::Schedule::OneDay; let mut interval = time::interval(schedule.to_duration());
  • Override this so that backup_interval is read from the TOML configuration and turned into the appropriate enum.
  1. Modify the code so that when the backup process starts, the program reads the configuration file and sets the backup interval based on the stored value.
  • Example of how this might be read:
let config_path = utils::path::get_config_path();
let config = toml::de::from_str(&fs::read_to_string(config_path).expect("Failed to read config file"))
.expect("Failed to parse TOML file");

let schedule = match config.intervalo_de_backup.as_str() {
"1day" => utils::schedule::Schedule::OneDay,
"7days" => utils::schedule::Schedule::SevenDays,
"1month" => utils::schedule::Schedule::OneMonth,
_ => utils::schedule::Schedule::OneDay, // Default value
};
  1. Create a new command in the CLI to allow the user to set the backup frequency directly, for example:
  • Command to set the backup interval:
purrgres --set-interval "7days"
  • This command should update the .config.toml file with the new interval value.
  1. Test the correct reading and setting of the values ​​and ensure that the change in the configuration file is reflected in the program's behavior.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions