kanit

Toy init system
Log | Files | Refs | README | LICENSE

list.rs (1063B)


      1 use std::fs;
      2 use std::path::Path;
      3 
      4 use kanit_common::constants;
      5 use kanit_common::error::{Context, Result, StaticError};
      6 use kanit_unit::formats::DependencyGrouping;
      7 
      8 use crate::flags::List;
      9 
     10 pub fn list(opts: List) -> Result<()> {
     11     let group_path = Path::new(constants::KAN_DEPENDENCY_MAP);
     12 
     13     if !group_path.exists() {
     14         Err(StaticError("failed to find dependency map"))?;
     15     }
     16 
     17     let group = fs::read_to_string(group_path)
     18         .context("failed to read dependency map")?
     19         .parse::<DependencyGrouping>()
     20         .context("failed to parse dependency map")?
     21         .groups;
     22 
     23     for (i, level) in group.iter() {
     24         println!("level {i}");
     25 
     26         if opts.plan {
     27             for (o, group) in level.iter().enumerate() {
     28                 println!("|> group {o}");
     29 
     30                 for unit in group.iter() {
     31                     println!("    |> {unit}");
     32                 }
     33             }
     34         } else {
     35             for unit in level.iter().flatten() {
     36                 println!("|> {unit}");
     37             }
     38         }
     39     }
     40 
     41     Ok(())
     42 }