File: container-pid.rs

package info (click to toggle)
rust-container-pid 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: makefile: 4
file content (32 lines) | stat: -rw-r--r-- 813 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use container_pid::{lookup_container_pid, lookup_container_type};
use std::env;
use std::process::exit;

pub fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() < 2 {
        eprintln!("USAGE: {} container-name [container-type]", args[0]);
        exit(1);
    }
    let types = if args.len() >= 3 {
        match lookup_container_type(&args[2]) {
            None => {
                eprintln!("unsupported container type: {}", args[2]);
                exit(1);
            }
            Some(c) => vec![c],
        }
    } else {
        vec![]
    };
    let name = &args[1];
    match lookup_container_pid(&name, &types) {
        Ok(pid) => {
            println!("{}", pid);
        }
        Err(e) => {
            eprintln!("{}", e);
            exit(1);
        }
    }
}