summary refs log tree commit diff
path: root/src/argument.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2019-07-31 17:07:27 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-06 19:23:06 +0000
commit267f2c80d1144e2eb7da1aca51c9c75eac186c77 (patch)
tree25e6584d8fe36a7e928892e1dc5f9796916a0714 /src/argument.rs
parent1e26230f3a490a7955d2ea9fe7855af5498ced70 (diff)
downloadcrosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar.gz
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar.bz2
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar.lz
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar.xz
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.tar.zst
crosvm-267f2c80d1144e2eb7da1aca51c9c75eac186c77.zip
split crosvm into a library and a main "crosvm" binary
This change has 3 parts:
- Modify the Cargo.toml to point at the bin and the lib source.
- Move modules and Config struct into the lib source
- Fix the argument/plugins module's doc comments which had never been
  tested.

The motivation for this change is to make testing crosvm's major
functionality (booting guest kernels, emulating hardware, etc) easier to
do from a cargo test. Being able to launce a crosvm config via the API
instead of the binary's command line will be possible with this change.

A side benefit is that this also enables doc tests in the lib side of
crosvm. The doc tests in binaries are not run due to a limitation in how
they get tested by cargo.

TEST=cargo test
     ./build_test
     kokoro/kokoro_simulator.sh
     emerge crosvm
BUG=None

Change-Id: I9d4b3a24231b895e8dfaf9e7b0f2b33350772041
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1730333
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'src/argument.rs')
-rw-r--r--src/argument.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/argument.rs b/src/argument.rs
index 7cb56d6..7106f8b 100644
--- a/src/argument.rs
+++ b/src/argument.rs
@@ -7,7 +7,9 @@
 //! # Example
 //!
 //! ```
-//! const ARGUMENTS: &'static [Argument] = &[
+//! # use crosvm::argument::{Argument, Error, print_help, set_arguments};
+//! # let args: std::slice::Iter<String> = [].iter();
+//! let arguments = &[
 //!     Argument::positional("FILES", "files to operate on"),
 //!     Argument::short_value('p', "program", "PROGRAM", "Program to apply to each file"),
 //!     Argument::short_value('c', "cpus", "N", "Number of CPUs to use. (default: 1)"),
@@ -15,7 +17,7 @@
 //!     Argument::short_flag('h', "help", "Print help message."),
 //! ];
 //!
-//! let match_res = set_arguments(args, ARGUMENTS, |name, value| {
+//! let match_res = set_arguments(args, arguments, |name, value| {
 //!     match name {
 //!         "" => println!("positional arg! {}", value.unwrap()),
 //!         "program" => println!("gonna use program {}", value.unwrap()),
@@ -31,11 +33,12 @@
 //!         "help" => return Err(Error::PrintHelp),
 //!         _ => unreachable!(),
 //!     }
-//! }
+//!     unreachable!();
+//! });
 //!
 //! match match_res {
 //!     Ok(_) => println!("running with settings"),
-//!     Err(Error::PrintHelp) => print_help("best_program", "FILES", ARGUMENTS),
+//!     Err(Error::PrintHelp) => print_help("best_program", "FILES", arguments),
 //!     Err(e) => println!("{}", e),
 //! }
 //! ```
@@ -93,28 +96,32 @@ pub type Result<T> = result::Result<T, Error>;
 /// To indicate a flag style argument:
 ///
 /// ```
-/// Argument::short_flag('f', "flag", "enable awesome mode")
+/// # use crosvm::argument::Argument;
+/// Argument::short_flag('f', "flag", "enable awesome mode");
 /// ```
 ///
 /// To indicate a parameter style argument that expects a value:
 ///
 /// ```
+/// # use crosvm::argument::Argument;
 /// // "VALUE" and "NETMASK" are placeholder values displayed in the help message for these
 /// // arguments.
-/// Argument::short_value('v', "val", "VALUE", "how much do you value this usage information")
-/// Argument::value("netmask", "NETMASK", "hides your netface")
+/// Argument::short_value('v', "val", "VALUE", "how much do you value this usage information");
+/// Argument::value("netmask", "NETMASK", "hides your netface");
 /// ```
 ///
 /// To indicate an argument with no short version:
 ///
 /// ```
-/// Argument::flag("verbose", "this option is hard to type quickly")
+/// # use crosvm::argument::Argument;
+/// Argument::flag("verbose", "this option is hard to type quickly");
 /// ```
 ///
 /// To indicate a positional argument:
 ///
 /// ```
-/// Argument::positional("VALUES", "these are positional arguments")
+/// # use crosvm::argument::Argument;
+/// Argument::positional("VALUES", "these are positional arguments");
 /// ```
 #[derive(Default)]
 pub struct Argument {