diff --git a/Cargo.toml b/Cargo.toml index cae0f71..ebfe1b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "rune" version = "0.1.2" +edition = "2021" authors = ["Alexander von Gluck IV "] license = "MIT" diff --git a/src/boards/mod.rs b/src/boards/mod.rs index ddfe5a2..91d2fd1 100644 --- a/src/boards/mod.rs +++ b/src/boards/mod.rs @@ -14,7 +14,7 @@ extern crate curl; use std::env; use std::error::Error; use curl::easy::Easy; -use fs::File; +use crate::fs::File; pub const MANIFEST_URI: &str = "https://github.com/haiku/firmware/raw/master/u-boot/manifest.json"; @@ -27,6 +27,27 @@ pub struct Board { pub files: Vec, } +// sort boards based on ID only +impl Ord for Board { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + (self.id).cmp(&(other.id)) + } +} + +impl PartialOrd for Board { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialEq for Board { + fn eq(&self, other: &Self) -> bool { + (self.id) == (other.id) + } +} + +impl Eq for Board {} + fn get_boards_local(path: String) -> Result, Box> { // Get boards from local manifest let file = File::open(path)?; @@ -60,6 +81,20 @@ pub fn get_boards() -> Result, Box> { } } +pub fn get_architectures() -> Result, Box> { + // TODO: this is horrible, we read board file like three times. + // Not so bad with local file, but CURLing it three times from Github is a bit... eh + let boards = get_boards()?; + let mut architectures: Vec = Vec::new(); + for i in boards { + if !architectures.contains(&i.arch) { + architectures.push(i.arch); + } + } + architectures.sort(); + return Ok(architectures) +} + pub fn get_arch(arch: String) -> Result, Box> { let boards = get_boards()?; let mut results: Vec = Vec::new(); @@ -68,6 +103,7 @@ pub fn get_arch(arch: String) -> Result, Box> { results.push(i); } } + results.sort(); return Ok(results) } @@ -81,14 +117,28 @@ pub fn get_board(board_id: String) -> Result> { return Err(From::from("Unknown target board!")); } -pub fn print(arch: String) { - print!("{}\n===\n", arch); - let arch_boards = match get_arch(arch) { - Ok(m) => { m }, +pub fn print() { + let architectures: Vec = match get_architectures() { + Ok(a) => {a}, Err(e) => { println!(" Error: {}", e); return }, }; + + if architectures.len() == 0 { + println!("No architectures were found"); + return + } + print!(" {:20} {:10} {:20}\n", "Board", "SOC", "Name"); - for board in arch_boards { - print!(" {:20} {:10} {:20}\n", board.id, board.soc, board.name); + for arch in architectures { + let arch_boards = match get_arch(arch.clone()) { + Ok(m) => { m }, + Err(e) => { println!(" Error: {}", e); return }, + }; + if arch_boards.len() > 0 { + print!("{}\n===\n", arch); + for board in arch_boards { + print!(" {:20} {:10} {:20}\n", board.id, board.soc, board.name); + } + } } } diff --git a/src/main.rs b/src/main.rs index 97240bb..216054d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ use fatfs::{BufStream, FileSystem, FsOptions}; use getopts::Options; use url::Url; use indicatif::{ProgressBar,ProgressStyle}; -use partition::Partition; +use crate::partition::Partition; use regex::Regex; mod boards; @@ -223,8 +223,7 @@ fn main() { print_version(); return; } else if matches.opt_present("l") { - //XXX This needs to be better and dynamic! - boards::print("arm".to_string()); + boards::print(); process::exit(1); }