Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Rust CI

on:
push:
branches: [main]
branches: [main, 4-fix-cargo-deny-in-sast-stage-of-rust-pipeline]
pull_request:
branches: [main]

Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
run: cargo install cargo-audit
- name: Run cargo-audit
run: cargo audit
# - name: Install cargo-deny
# run: cargo install cargo-deny
# - name: Run cargo-deny
# run: cargo deny check
- name: Install cargo-deny
run: cargo install cargo-deny
- name: Run cargo-deny
run: cargo deny check
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "rustroika"
version = "2.0.0"
version = "2.1.0"
edition = "2024"
license = "Apache-2.0"
license = "MIT OR Apache-2.0"
description = "A utility to compare public transport costs"
authors = ["Ivan King"]
authors = ["Ivan 'oosama' King"]

[dependencies]
clap = { version = "4.5.35", features = ["derive"] }
clap = { version = "4.5.35", features = ["derive", "cargo"] }
clap_derive = { version = "4.0.0-rc.1" }
colored = "3.0.0"
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[licenses]
allow = ["MIT", "Apache-2.0", "MPL-2.0", "Unicode-3.0", "Unicode-DFS-2016"]
82 changes: 54 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,60 @@ fn main() {
let individual_cost =
full_price_count * args.ticket_price + discounted_count * (args.ticket_price / 2);

println!(
"\n╭{}╴{}╴{}╴{}╴╮",
"─".repeat(14),
"─".repeat(10),
"─".repeat(14),
"─".repeat(17)
);
println!(
"│ {:14} │ {:10} │ {:14} │ {:10} │",
"Total trips".cyan().bold(),
"Monthly".cyan().bold(),
"Individual".cyan().bold(),
"Ticket".cyan().bold()
);
println!(
"│ {:14} │ {:>10} │ {:>14} │ {:>10} │",
format!("{}", total_trips).yellow(),
format!("{} RUB", args.monthly_cost).yellow(),
format!("{} RUB", individual_cost).yellow(),
format!("{} RUB", args.ticket_price).yellow()
);
println!(
"╰{}╴{}╴{}╴{}╯",
"─".repeat(14),
"─".repeat(10),
"─".repeat(14),
"─".repeat(18)
);
let col1_data_plain = total_trips.to_string();
let col2_data_plain = format!("{} RUB", args.monthly_cost);
let col3_data_plain = format!("{} RUB", individual_cost);
let col4_data_plain = format!("{} RUB", args.ticket_price);

let headers = ["Total Trips", "Monthly", "Individual", "Ticket"];
let data = [
&col1_data_plain,
&col2_data_plain,
&col3_data_plain,
&col4_data_plain,
];
let col_widths: Vec<usize> = headers
.iter()
.zip(data.iter())
.map(|(h, d)| h.len().max(d.len()))
.collect();

let make_border = |left: &str, middle: &str, right: &str| {
let mut parts = Vec::new();
for &w in &col_widths {
parts.push("─".repeat(w + 2));
}
format!("{}{}{}", left, parts.join(middle), right)
};

let top_border = make_border("╭", "┬", "╮");
let middle_border = make_border("├", "┼", "┤");
let bottom_border = make_border("╰", "┴", "╯");

let header_row = headers
.iter()
.enumerate()
.map(|(i, &h)| format!(" {:^width$} ", h.cyan().bold(), width = col_widths[i]))
.collect::<Vec<_>>()
.join("│");

let data_row = [
col1_data_plain.yellow(),
col2_data_plain.yellow(),
col3_data_plain.yellow(),
col4_data_plain.yellow(),
]
.iter()
.enumerate()
.map(|(i, cell)| format!(" {:^width$} ", cell, width = col_widths[i]))
.collect::<Vec<_>>()
.join("│");

println!("\n{}", top_border);
println!("│{}│", header_row);
println!("{}", middle_border);
println!("│{}│", data_row);
println!("{}", bottom_border);

let message = match individual_cost.cmp(&args.monthly_cost) {
std::cmp::Ordering::Less => format!(
Expand Down