Skip to content

Commit c88da08

Browse files
committed
Refactor enum display
1 parent 26874d3 commit c88da08

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl Config {
339339

340340
let license_label = "License";
341341
if let Some(license) = config.license {
342-
println!("{}: {:?}", license_label.blue(), license);
342+
println!("{}: {}", license_label.blue(), license);
343343
} else {
344344
println!("{}: null", license_label.blue());
345345
}
@@ -379,7 +379,7 @@ impl Config {
379379

380380
let project_manager_label = "Project Manager";
381381
if let Some(project_manager) = config.project_manager {
382-
println!("{}: {:?}", project_manager_label.blue(), project_manager);
382+
println!("{}: {}", project_manager_label.blue(), project_manager);
383383
} else {
384384
println!("{}: null", project_manager_label.blue());
385385
}
@@ -401,7 +401,7 @@ impl Config {
401401
let dependabot_schedule_label = "Dependabot Schedule";
402402
if let Some(dependabot_schedule) = config.dependabot_schedule {
403403
println!(
404-
"{}: {:?}",
404+
"{}: {}",
405405
dependabot_schedule_label.blue(),
406406
dependabot_schedule
407407
);
@@ -411,7 +411,7 @@ impl Config {
411411

412412
let dependabot_day_label = "Dependabot Day";
413413
if let Some(dependabot_day) = config.dependabot_day {
414-
println!("{}: {:?}", dependabot_day_label.blue(), dependabot_day);
414+
println!("{}: {}", dependabot_day_label.blue(), dependabot_day);
415415
} else {
416416
println!("{}: null", dependabot_day_label.blue());
417417
}

src/project_generator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ fn build_latest_pre_commit_dependencies(
213213
hooks.par_iter_mut().for_each(|hook| {
214214
if hook.get_latest_version().is_err() {
215215
let error_message = format!(
216-
"Error retrieving latest pre-commit version for {:?}. Using default.",
217-
hook.hook.to_string()
216+
"Error retrieving latest pre-commit version for {}. Using default.",
217+
hook.hook
218218
);
219219
println!("\n{}", error_message.yellow());
220220
}
@@ -296,8 +296,8 @@ fn build_latest_dev_dependencies(
296296
packages.par_iter_mut().for_each(|package| {
297297
if package.get_latest_version().is_err() {
298298
let error_message = format!(
299-
"Error retrieving latest python package version for {:?}. Using default.",
300-
package.package.to_string()
299+
"Error retrieving latest python package version for {}. Using default.",
300+
package.package
301301
);
302302
println!("\n{}", error_message.yellow());
303303
}

src/project_info.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use std::io::Write;
2-
use std::path::{Path, PathBuf};
1+
use std::{
2+
fmt,
3+
io::Write,
4+
path::{Path, PathBuf},
5+
};
36

47
use anyhow::{bail, Result};
58
use clap::ValueEnum;
@@ -15,6 +18,16 @@ pub enum DependabotSchedule {
1518
Monthly,
1619
}
1720

21+
impl fmt::Display for DependabotSchedule {
22+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23+
match self {
24+
DependabotSchedule::Daily => write!(f, "Daily"),
25+
DependabotSchedule::Weekly => write!(f, "Weekly"),
26+
DependabotSchedule::Monthly => write!(f, "Montly"),
27+
}
28+
}
29+
}
30+
1831
#[derive(Clone, Debug, Deserialize, Serialize, ValueEnum)]
1932
pub enum Day {
2033
Monday,
@@ -26,20 +39,54 @@ pub enum Day {
2639
Sunday,
2740
}
2841

42+
impl fmt::Display for Day {
43+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44+
match self {
45+
Day::Monday => write!(f, "Monday"),
46+
Day::Tuesday => write!(f, "Tuesday"),
47+
Day::Wednesday => write!(f, "Wednesday"),
48+
Day::Thursday => write!(f, "Thursday"),
49+
Day::Friday => write!(f, "Friday"),
50+
Day::Saturday => write!(f, "Saturday"),
51+
Day::Sunday => write!(f, "Sunday"),
52+
}
53+
}
54+
}
55+
2956
#[derive(Clone, Debug, Deserialize, Serialize, ValueEnum)]
3057
pub enum LicenseType {
3158
Mit,
3259
Apache2,
3360
NoLicense,
3461
}
3562

63+
impl fmt::Display for LicenseType {
64+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65+
match self {
66+
LicenseType::Mit => write!(f, "MIT"),
67+
LicenseType::Apache2 => write!(f, "Apache 2.0"),
68+
LicenseType::NoLicense => write!(f, "No License"),
69+
}
70+
}
71+
}
72+
3673
#[derive(Clone, Debug, Deserialize, Serialize, ValueEnum)]
3774
pub enum ProjectManager {
3875
Maturin,
3976
Poetry,
4077
Setuptools,
4178
}
4279

80+
impl fmt::Display for ProjectManager {
81+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82+
match self {
83+
ProjectManager::Maturin => write!(f, "Maturin"),
84+
ProjectManager::Poetry => write!(f, "Poetry"),
85+
ProjectManager::Setuptools => write!(f, "Setuptools"),
86+
}
87+
}
88+
}
89+
4390
struct Prompt {
4491
prompt_text: String,
4592
default: Option<String>,
@@ -278,7 +325,7 @@ fn copyright_year_prompt(license: &LicenseType, default: Option<String>) -> Resu
278325

279326
if input.is_empty() {
280327
bail!(format!(
281-
"A copyright year is required for {:?} license",
328+
"A copyright year is required for {} license",
282329
license
283330
));
284331
} else {

src/rust_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn build_latest_dependencies(min_python_version: &str, download_latest_packages:
2020
packages.par_iter_mut().for_each(|package| {
2121
if package.get_latest_version().is_err() {
2222
let error_message = format!(
23-
"Error retrieving latest crate version for {:?}. Using default.",
23+
"Error retrieving latest crate version for {}. Using default.",
2424
package.name
2525
);
2626
println!("\n{}", error_message.yellow());

0 commit comments

Comments
 (0)