Skip to content

Commit e61c2c0

Browse files
committed
Add --print-config flag.
Fix typo in help message
1 parent 8d68bef commit e61c2c0

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Author: Tejas Gudgunti
2+
/* TODO:
3+
*/
24

35
//! This is one of my first rust projects, and is therefore not very idiomatic.
46
//! The code contains lots of repetition, and other generally *bad* coding practices.
@@ -50,7 +52,7 @@ struct Cli {
5052
#[arg(long, groups = ["main", "yearmonth"])]
5153
gen_report: bool,
5254

53-
/// Opens the respective configuration file: ./jrnl/config.toml
55+
/// Opens the configuration file: ~/.config/jrnl/config.toml
5456
#[arg(long, group = "main")]
5557
open_config: bool,
5658

@@ -61,6 +63,10 @@ struct Cli {
6163
/// Provide a path to search for the directory `jrnl`.
6264
#[arg(short, long, default_missing_value=Some("."), num_args=0..=1)]
6365
path: Option<String>,
66+
67+
/// Print the current configuration
68+
#[arg(long, group = "main")]
69+
print_config: bool,
6470
}
6571

6672
fn main() {
@@ -202,11 +208,16 @@ fn main() {
202208
.expect("Failed to execute process");
203209
}
204210

211+
if args.print_config {
212+
println!("{}", read_config().0);
213+
}
214+
205215
if args_tag == ""
206216
&& args_entry == ""
207217
&& args_open_entry == ""
208218
&& !args.gen_report
209219
&& !args.open_config
220+
&& !args.print_config
210221
&& args_search == ""
211222
{
212223
let today_date = today.format("%Y-%m-%d").to_string();

src/utils.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ pub struct Config {
5858
pub approx_variation: u32,
5959
}
6060

61+
impl std::fmt::Display for Config {
62+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
63+
let mut table = Table::new();
64+
table
65+
.load_preset(UTF8_FULL)
66+
.apply_modifier(UTF8_ROUND_CORNERS)
67+
.set_content_arrangement(ContentArrangement::Dynamic)
68+
.set_header(vec!["Quantities".green(), "Value".green()]);
69+
table.add_row(vec!["Add Weekday", &self.add_weekday.to_string()]);
70+
table.add_row(vec!["Add Food Column", &self.add_food_column.to_string()]);
71+
table.add_row(vec!["Add timestamp", &self.add_timestamp.to_string()]);
72+
table.add_row(vec!["Default Editor", &self.editor.to_string()]);
73+
table.add_row(vec!["Default Pager", &self.pager.to_string()]);
74+
table.add_row(vec![
75+
"Max rows to display for tags",
76+
&self.max_rows.to_string(),
77+
]);
78+
table.add_row(vec!["When to use pager", &self.when_pager.to_string()]);
79+
table.add_row(vec!["Default path", &self.default_path.to_string()]);
80+
table.add_row(vec![
81+
"Approximation sensitivity ",
82+
&self.approx_variation.to_string(),
83+
]);
84+
write!(
85+
f,
86+
"{}\n{}",
87+
"CONFIGURATION".cyan().bold().underline(),
88+
table
89+
)
90+
}
91+
}
92+
6193
/// Returns all headings(`# <stuff>`) and their corresponding line numbers
6294
/// as a tuple: (headings, corresponding_line_no)
6395
pub fn get_headings(filename: &str) -> (Vec<String>, Vec<u32>) {

0 commit comments

Comments
 (0)