Skip to content

Commit

Permalink
Merge pull request #32 from learturely/worksoup-main
Browse files Browse the repository at this point in the history
优化输出。
  • Loading branch information
worksoup authored May 14, 2024
2 parents 94b1b8b + 9c5913d commit 83fab2f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/cli/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ pub enum MainCommand {
/// 列出指定课程的位置。
#[arg(short, long)]
course: Option<i64>,
/// 以更好的格式显示结果。
#[arg(short, long)]
pretty: bool,
/// 精简显示结果。
#[arg(short, long)]
short: bool,
},
/// 显示配置文件夹位置。
WhereIsConfig,
Expand Down
101 changes: 72 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const NOTICE: &str = r#"
fn main() {
let env = env_logger::Env::default().filter_or("RUST_LOG", "info");
let mut builder = env_logger::Builder::from_env(env);
builder.target(env_logger::Target::Stdout);
// builder.target(env_logger::Target::Stdout);
builder.init();
let args = <Args as clap::Parser>::parse();
let Args {
Expand Down Expand Up @@ -125,7 +125,7 @@ fn main() {
// 列出所有账号。
let accounts = table.get_accounts();
for a in accounts {
info!("{}, {}", a.0.uname, a.1);
println!("{}, {}", a.0.uname, a.1);
}
}
MainCommand::Courses { accounts } => {
Expand All @@ -142,38 +142,81 @@ fn main() {
let courses = cxsign::Course::get_courses(sessions.values()).unwrap_or_default();
// 列出所有课程。
for (c, _) in courses {
info!("{}", c);
println!("{}", c);
}
}
MainCommand::Location { command } => {
cli::location::parse_location_sub_command(&db, command)
}
MainCommand::Locations { global, course } => {
MainCommand::Locations {
global,
course,
pretty,
short,
} => {
let location_table = LocationTable::from_ref(&db);
let alias_table = AliasTable::from_ref(&db);
let course_id = course.or(if global { Some(-1) } else { None });
if let Some(course_id) = course_id {
// 列出指定课程的位置。
let locations = location_table.get_location_map_by_course(course_id);
for (location_id, location) in locations {
info!(
"位置id: {}, 位置: {},\n\t别名: {:?}",
location_id,
location,
alias_table.get_aliases(location_id)
)
if short {
let locations = if let Some(course_id) = course_id {
location_table.get_location_map_by_course(course_id)
} else {
location_table
.get_locations()
.into_iter()
.map(|(k, v)| (k, v.1))
.collect()
};
for (_, location) in locations {
println!("{}", location,)
}
} else {
// 列出所有位置。
let locations = location_table.get_locations();
for (location_id, (course_id, location)) in locations {
info!(
"位置id: {}, 课程号: {}, 位置: {},\n\t别名: {:?}",
location_id,
course_id,
location,
alias_table.get_aliases(location_id)
)
if let Some(course_id) = course_id {
// 列出指定课程的位置。
let locations = location_table.get_location_map_by_course(course_id);
if pretty {
for (location_id, location) in locations {
println!(
"位置id: {}, 位置: {},\n\t别名: {:?}",
location_id,
location,
alias_table.get_aliases(location_id)
)
}
} else {
for (location_id, location) in locations {
println!(
"{}${}${:?}",
location_id,
location,
alias_table.get_aliases(location_id)
)
}
}
} else {
// 列出所有位置。
let locations = location_table.get_locations();
if pretty {
for (location_id, (course_id, location)) in locations {
println!(
"位置id: {}, 课程号: {}, 位置: {},\n\t别名: {:?}",
location_id,
course_id,
location,
alias_table.get_aliases(location_id)
)
}
} else {
for (location_id, (course_id, location)) in locations {
println!(
"{}${}${}${:?}",
location_id,
course_id,
location,
alias_table.get_aliases(location_id)
)
}
}
}
}
}
Expand All @@ -199,14 +242,14 @@ fn main() {
// 列出指定课程的有效签到。
for a in a {
if a.course.get_id() == course {
info!("{}", a.fmt_without_course_info());
println!("{}", a.fmt_without_course_info());
}
}
if all {
// 列出指定课程的所有签到。
for a in n {
if a.course.get_id() == course {
info!("{}", a.fmt_without_course_info());
println!("{}", a.fmt_without_course_info());
}
}
}
Expand All @@ -223,20 +266,20 @@ fn main() {
});
// 列出所有有效签到。
for a in available_sign_activities {
info!("{}", a.0.as_inner());
println!("{}", a.0.as_inner());
}
if all {
// 列出所有签到。
for a in other_sign_activities {
info!("{}", a.0.as_inner());
println!("{}", a.0.as_inner());
}
} else {
warn!("{NOTICE}");
}
}
}
MainCommand::WhereIsConfig => {
info!(
println!(
"{}",
&DIR.get_config_dir()
.into_os_string()
Expand Down

0 comments on commit 83fab2f

Please sign in to comment.