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
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.
## Patch format

View File

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