Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: watch command #78

Merged
merged 1 commit into from
Nov 6, 2023
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
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;
}
})
}
Loading