Skip to content

Commit

Permalink
feat: watch command
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Nov 5, 2023
1 parent 196c005 commit 88d9d8a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/opup/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub enum Command {
Clean,
/// List op-up docker containers
List,
/// Watch the devnet stack components.
/// This will output a refreshed view of the stack components
/// as they come online.
Watch,
/// Install Dependencies
Deps,
}
Expand All @@ -38,15 +42,14 @@ pub fn run() -> Result<()> {

crate::telemetry::init_tracing_subscriber(v)?;

crate::banners::banner()?;

// Dispatch on the specified subcommand,
// running the `up` subcommand by default.
match command {
None => UpCommand::new(None, false).run(),
Some(command) => match command {
Command::Up(up_command) => up_command.run(),
Command::List => crate::list::run(),
Command::Watch => crate::watch::run(),
Command::Down => unimplemented!("down command not yet implemented"),
Command::Nuke => unimplemented!("nuke command not yet implemented"),
Command::Clean => unimplemented!("clean command not yet implemented"),
Expand Down
1 change: 1 addition & 0 deletions bin/opup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pub(crate) mod list;
pub(crate) mod runner;
pub(crate) mod telemetry;
pub(crate) mod up;
pub(crate) mod watch;
2 changes: 2 additions & 0 deletions bin/opup/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ impl UpCommand {
/// Entrypoint
#[instrument(name = "up", target = "run", skip(self))]
pub fn run(&self) -> Result<()> {
crate::banners::banner()?;

crate::runner::run_until_ctrl_c(async { self.execute().await })
}
}
37 changes: 37 additions & 0 deletions bin/opup/src/watch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use eyre::Result;
use std::time::Duration;

pub(crate) fn run() -> Result<()> {
crate::runner::run_until_ctrl_c(async {
loop {
// clear the terminal and reset the cursor to the top left
print!("\x1B[2J\x1B[1;1H");

let containers = op_composer::Composer::new()?
.list_containers(Some("running"))
.await?;

let mut table = prettytable::Table::new();
table.set_titles(prettytable::row!["Name", "Image", "Status", "Up Time"]);
for container in containers {
table.add_row(prettytable::row![
container
.names
.map(|n| n.join(", "))
.unwrap_or_else(|| "none".to_string()),
container.image.unwrap_or_else(|| "none".to_string()),
container.status.unwrap_or_else(|| "none".to_string()),
container
.created
.map(|created| humantime::format_duration(Duration::from_secs(
created as u64
))
.to_string())
.unwrap_or_else(|| "unknown".to_string())
]);
}
table.printstd();
tokio::time::sleep(Duration::from_secs(2)).await;
}
})
}

0 comments on commit 88d9d8a

Please sign in to comment.