Skip to content

Commit

Permalink
feat: Init read_data func
Browse files Browse the repository at this point in the history
  • Loading branch information
haruki7049 committed Jul 4, 2024
1 parent d705898 commit b2674c8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use crate::data::DataTable;
use clap::Parser;

/// set_income subcommand
pub fn set_income() {
Expand Down Expand Up @@ -31,6 +31,21 @@ fn write_data(data: DataTable, path: String) {
}
}

fn read_data(path: String) -> DataTable {
let string = match std::fs::read_to_string(path) {
Ok(s) => s,
Err(err) => {
panic!("Failed to read data from file: {}", err);
}
};
match toml::from_str(&string) {
Ok(data) => data,
Err(err) => {
panic!("Failed to parse data from file: {}", err);
}
}
}

/// SET_INCOME constant
const SET_INCOME: &str = "set-income";

Expand Down

0 comments on commit b2674c8

Please sign in to comment.