Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
implement print pidfile as table
Browse files Browse the repository at this point in the history
  • Loading branch information
guni1192 committed Mar 16, 2019
1 parent 4ec2301 commit 54b87f7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ dirs = "1.0"
log = "0.4"
env_logger = "0.6.0"
rand = "0.6"
prettytable-rs = "^0.8"
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[macro_use]
extern crate serde_derive;
extern crate env_logger;

#[macro_use]
extern crate prettytable;
use std::process::exit;

use clap::{crate_name, crate_version, App, Arg, SubCommand};
Expand All @@ -13,6 +14,7 @@ mod container;
mod image;
mod mounts;
mod network;
mod pids;
mod runner;

fn main() {
Expand Down Expand Up @@ -72,11 +74,17 @@ fn main() {
.takes_value(true),
),
)
.subcommand(
SubCommand::with_name("ps")
.version(crate_version!())
.about("show containers"),
)
.get_matches();

match &app_matches.subcommand() {
("run", Some(sub_m)) => runner::run(&sub_m),
("pull", Some(sub_m)) => runner::pull(&sub_m),
("ps", Some(sub_m)) => pids::show(&sub_m),
_ => {
eprintln!("Unexpected arguments");
app.print_help().unwrap();
Expand Down
33 changes: 33 additions & 0 deletions src/pids.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::path::Path;

use clap::ArgMatches;
use prettytable::{Cell, Row, Table};

use nix::unistd::Pid;

pub fn show(sub_m: &ArgMatches) {
// Create the table
let mut table = Table::new();

table.add_row(row!["Container ID", "PID"]);
for i in 0..3 {
let pidfile = Pidfile::read(Path::new("/hoge"));
table.add_row(row![pidfile.name, pidfile.pid]);
}

table.printstd();
}

struct Pidfile {
pid: Pid,
name: String,
}

impl Pidfile {
fn read(path: &Path) -> Self {
Pidfile {
pid: Pid::from_raw(1000),
name: "library/alpine:latest".to_string(),
}
}
}

0 comments on commit 54b87f7

Please sign in to comment.