Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update branch. #33

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading