main: refactored parameter parsing

CONTRIBUTING.md: removed a space to suport markdown linking

Refactored cmdline and net_params arguments to use option adapters
to achieve the same parsed results in a "more rusty" way.

Deleted a space in the contributing markdown to link properly.

Signed-off-by: Logan Saso <logansaso+tech@gmail.com>
This commit is contained in:
Logan Saso 2019-05-16 10:53:57 -07:00 committed by Rob Bradford
parent 9299502955
commit e52132c8c8
2 changed files with 16 additions and 25 deletions

View File

@ -10,7 +10,7 @@ for each submitted Pull Request (PR).
## Certificate of Origin ## Certificate of Origin
In order to get a clear contribution chain of trust we use the [signed-off-by language] (https://01.org/community/signed-process) In order to get a clear contribution chain of trust we use the [signed-off-by language](https://01.org/community/signed-process)
used by the Linux kernel project. used by the Linux kernel project.
## Patch format ## Patch format

View File

@ -75,38 +75,29 @@ fn main() {
.expect("Missing argument: disk"); .expect("Missing argument: disk");
let disk_path = disk_arg.as_path(); let disk_path = disk_arg.as_path();
let cmdline = if cmd_arguments.is_present("cmdline") { let cmdline = cmd_arguments
cmd_arguments
.value_of("cmdline") .value_of("cmdline")
.map(std::string::ToString::to_string) .map(std::string::ToString::to_string)
.unwrap() .unwrap_or_else(String::new);
} else {
String::new()
};
let mut net_params = None; let net_params = cmd_arguments
if cmd_arguments.is_present("net") { .value_of("net")
if let Some(net) = cmd_arguments.value_of("net") { .map(std::string::ToString::to_string);
net_params = Some(net.to_string());
} else {
net_params = Some(String::new())
}
}
let rng_path = match cmd_arguments.occurrences_of("rng") { let rng_path = match cmd_arguments.occurrences_of("rng") {
0 => None, 0 => None,
_ => Some(cmd_arguments.value_of("rng").unwrap().to_string()), _ => Some(cmd_arguments.value_of("rng").unwrap().to_string()),
}; };
let mut vcpus = DEFAULT_VCPUS; let vcpus = cmd_arguments
if let Some(cpus) = cmd_arguments.value_of("cpus") { .value_of("cpus")
vcpus = cpus.parse::<u8>().unwrap(); .and_then(|c| c.parse::<u8>().ok())
} .unwrap_or(DEFAULT_VCPUS);
let mut memory = DEFAULT_MEMORY; let memory = cmd_arguments
if let Some(mem) = cmd_arguments.value_of("memory") { .value_of("memory")
memory = mem.parse::<u64>().unwrap(); .and_then(|m| m.parse::<u64>().ok())
} .unwrap_or(DEFAULT_MEMORY);
println!( println!(
"Cloud Hypervisor Guest\n\tvCPUs: {}\n\tMemory: {} MB\n\tKernel: {:?}\n\tKernel cmdline: {}\n\tDisk: {:?}", "Cloud Hypervisor Guest\n\tvCPUs: {}\n\tMemory: {} MB\n\tKernel: {:?}\n\tKernel cmdline: {}\n\tDisk: {:?}",