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

Commit

Permalink
add cmd line option parser
Browse files Browse the repository at this point in the history
  • Loading branch information
guni973 committed Sep 26, 2018
1 parent c82432d commit ecbec69
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
16 changes: 16 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 @@ -6,3 +6,4 @@ edition = "2018"

[dependencies]
nix = "0.11.0"
getopts = "0.2"
28 changes: 21 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ use nix::mount::{mount, MsFlags};
use nix::sched::*; // 調べる
use nix::sys::wait::*;
use nix::unistd::*;
use nix::unistd::*;
use nix::unistd::{execv, fork, ForkResult};
// use nix::unistd::{execv, fork, ForkResult};
use getopts::Options;
use std::env::{args, set_var};
use std::ffi::CString;
use std::fs;
use std::process::*;

fn print_help() {}
fn print_help() {
println!("help message");
}

// TODO Bootstrap func

Expand All @@ -18,13 +20,25 @@ fn main() {
set_var("RUST_BACKTRACE", "1");

let args: Vec<String> = args().collect();
if args.len() < 2 {
eprintln!("invalid argments");

let mut opts = Options::new();
opts.optopt("", "path", "set container path", "CONTAINER PATH");
opts.optflag("h", "help", "print help message");

let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!(f.to_string()),
};
if matches.opt_present("h") {
print_help();
exit(1);
return;
}

let container_path = args[1].as_str();
let container_path = matches.opt_str("path").unwrap();
let container_path = container_path.as_str();

println!("{:?}", container_path);
// let container_path = args[1].as_str();

match unshare(CloneFlags::CLONE_NEWPID | CloneFlags::CLONE_NEWNS) {
Ok(_) => {}
Expand Down

0 comments on commit ecbec69

Please sign in to comment.