Skip to content

Commit

Permalink
add follow logs command
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaromiq committed Sep 30, 2020
1 parent 5192569 commit bf346cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ $ adh --help
--database_name Optional. Allows you to specify the name of a database to be created on image startup
--root_password Optional. Specifies the password that will be set for the MySQL root superuser account
If not set, a random password will be created and printed at the end
start <container_id> Start container with given id, if container_id is not provider, user can select from a list
stop <container_id> Stop container with given id, if container_id is not provider, user can select from a list
start <container_id> Start container with id container_id, if container_id is not provider, user can select from a list
stop <container_id> Stop container with id container_id, if container_id is not provider, user can select from a list
ps Formatted ps for running dockers
psa Formatted ps for all dockers
rc Remove all containers
Expand All @@ -40,6 +40,8 @@ $ adh --help
rec Remove exited containers
kc Kill all containers
remove-volumes Remove all volumes
log <container_id> Show container logs with id container_id, if container_id is not provider, user can select from a list
flog <container_id> Show container logs in follow mode with id container_id, if container_id is not provider, user can select from a list
Options:
Expand Down
10 changes: 5 additions & 5 deletions src/commands/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use async_trait::async_trait;
use clap::ArgMatches;

use crate::commands::create_local_registry::LocalRegistry;
use crate::commands::kc::KillContainers;
use crate::commands::logs::Logs;
use crate::commands::mysql::Mysql;
use crate::commands::nginx::Nginx;
use crate::commands::ps::Ps;
use crate::commands::psa::Psa;
use crate::commands::rc::RemoveContainers;
use crate::commands::remove_none_images::RemoveNoneImages;

use crate::commands::kc::KillContainers;
use crate::commands::logs::Logs;
use crate::commands::remove_exited_containers::RemoveExitedContainers;
use crate::commands::remove_none_images::RemoveNoneImages;
use crate::commands::remove_volumes::RemoveVolumes;
use crate::commands::ri::RemoveImages;
use crate::commands::start::Start;
Expand Down Expand Up @@ -58,7 +57,8 @@ pub fn from(matches: ArgMatches) -> Box<dyn Command> {
Some("rec") => Box::new(RemoveExitedContainers),
Some("kc") => Box::new(KillContainers),
Some("remove-volumes") => Box::new(RemoveVolumes),
Some("log") => Box::new(Logs),
Some("flog") => Box::new(Logs { follow: true }),
Some("log") => Box::new(Logs { follow: false }),
_ => Box::new(Noop),
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/commands/logs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use async_trait::async_trait;
use futures::StreamExt;
use shiplift::tty::TtyChunk;
use shiplift::{Docker, LogsOptions};
use shiplift::tty::TtyChunk;

use crate::commands::command::Command;
use crate::infra::container_repository::get_all_containers;
use crate::infra::container_selector::select_container;

pub struct Logs;
pub struct Logs {
pub(crate) follow: bool,
}

#[async_trait]
impl Command for Logs {
Expand All @@ -17,7 +19,7 @@ impl Command for Logs {
let docker = Docker::new();
let mut logs_stream = docker.containers().get(&selected).logs(
&LogsOptions::builder()
.follow(true)
.follow(self.follow)
.stdout(true)
.stderr(true)
.build(),
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ async fn main() {
.about("Remove all volumes"))
.subcommand(SubCommand::with_name("log")
.about("Show docker logs"))
.subcommand(SubCommand::with_name("flog")
.about("Show docker logs and listen the changes"))
.get_matches();

from(matches).execute().await;
Expand Down

0 comments on commit bf346cb

Please sign in to comment.