Skip to content

Commit

Permalink
new: simplified view
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Nov 1, 2024
1 parent ae998ae commit 1bebaf3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 114 deletions.
88 changes: 0 additions & 88 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ actix-web-lab = "0.23.0"
anyhow = "1.0.90"
camino = { version = "1.1.9", features = ["serde"] }
clap = { version = "4.5.20", features = ["derive"] }
comfy-table = "7.1.1"
env_logger = "0.11.5"
futures = "0.3.31"
glob = "0.3.1"
Expand Down
2 changes: 1 addition & 1 deletion src/book/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ExecutionFlavor {
match self {
Self::Shell(shell) => shell.to_string(),
Self::Sudo => "sudo".to_string(),
Self::Docker(_) => "docker".to_string(),
Self::Docker(image) => format!("docker {}", image),
Self::Error(message) => message.to_string(),
}
}
Expand Down
39 changes: 15 additions & 24 deletions src/cli/view.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
use comfy_table::Table;

use crate::book::{runtime::ExecutionFlavor, Book};

use super::ViewArgs;

pub(crate) async fn view(args: ViewArgs) -> anyhow::Result<()> {
let book = Book::from_path(args.path, args.filter)?;

let mut table = Table::new();

table.set_header(vec!["page", "function", "context", "description"]);

for (_, page) in book.pages {
let mut first_page = true;
println!("{} > [{}]", page.categories.join(" > "), page.name);

for (function_name, function) in page.functions {
if first_page {
table.add_row(vec![
format!("{} > {}", page.categories.join(" > "), &page.name),
function_name,
ExecutionFlavor::for_function(&function)?.to_string(),
function.description,
]);
first_page = false;
} else {
table.add_row(vec![
"".to_owned(),
function_name,
ExecutionFlavor::for_function(&function)?.to_string(),
function.description,
]);
println!(" * {} : {}", function_name, function.description);
println!(
" running with: {}",
ExecutionFlavor::for_function(&function)?.to_string()
);
println!(" parameters:");
for (parameter_name, parameter) in &function.parameters {
println!(
" {{${}}} : {}",
parameter_name, parameter.description
);
}

println!();
}
}

println!("\n{}", table);

Ok(())
}

0 comments on commit 1bebaf3

Please sign in to comment.