diff --git a/load/Cargo.toml b/load/Cargo.toml index 7c3c6a2..74254e2 100644 --- a/load/Cargo.toml +++ b/load/Cargo.toml @@ -4,9 +4,6 @@ version = "0.8.1-development" authors = ["Brian Pearce"] publish = false -[lib] -doctest = false - [dependencies] common = { path = "../common" } dirs = "2.0.2" diff --git a/load/src/project/mod.rs b/load/src/project/mod.rs index 36e1248..cc87850 100644 --- a/load/src/project/mod.rs +++ b/load/src/project/mod.rs @@ -19,17 +19,35 @@ static TMUX_ENV_VAR: &str = "TMUX"; /// Read in the contents of the config (which should be Yaml), and parse the /// contents as yaml. /// +/// `project_name`: The name of the project, corresponding to the project config +/// file. +/// `project_paths`: The struct of paths +/// /// # Examples /// /// Given the project name "compiler" and a project file found at: /// `~/.muxed/compiler.yml`. /// -/// ``` -/// let yaml: Result, String> = read("compiler".to_string()); -/// ``` +/// ```rust,no_run +/// extern crate common; +/// extern crate load; +/// extern crate yaml_rust; /// -/// `project_name`: The name of the project, corresponding to the project config -/// file. +/// use common::project_paths::ProjectPaths; +/// use load::project::read; +/// use std::path::PathBuf; +/// use yaml_rust::{Yaml, YamlLoader}; +/// +/// let paths = ProjectPaths::new( +/// PathBuf::from("/tmp"), +/// PathBuf::from("/tmp/.muxed"), +/// PathBuf::from("/tmp/.muxed/projectname.yml") +/// ); +/// +/// let yaml: Result, String> = read("compiler", &paths); +/// +/// assert!(yaml.is_ok()); +/// ``` pub fn read(project_name: &str, project_paths: &ProjectPaths) -> Result, String> { check_first_run(&project_paths.project_directory)?; @@ -57,6 +75,22 @@ pub fn session_exists(project_name: &str) -> Option { /// Check to see how we want to open the project. Do we need to attach to a new /// tmux session or can we switch the client from a running session. +/// +/// # Examples +/// +/// ```rust +/// extern crate load; +/// +/// use load::command::{Attach, Commands, Command}; +/// use load::project::open; +/// +/// let correct_type = match open("muxed") { +/// Commands::Attach(_) => true, +/// _ => false, +/// }; +/// +/// assert!(correct_type) +/// ``` pub fn open(project_name: &str) -> Commands { if env::var_os(TMUX_ENV_VAR).is_some() { SwitchClient::new(&project_name).into() diff --git a/load/src/tmux/mod.rs b/load/src/tmux/mod.rs index cf303aa..90a672f 100644 --- a/load/src/tmux/mod.rs +++ b/load/src/tmux/mod.rs @@ -25,8 +25,12 @@ static TMUX_NAME: &str = "tmux"; /// /// # Examples /// -/// ``` -/// let _ = call(&["new-window", "-t", "muxed", "-c", "~/Projects/muxed/"]); +/// ```rust +/// extern crate load; +/// use load::tmux::call; +/// +/// let _ = call(&["new-window", "-t", "muxed-test", "-c", "~/Projects/muxed/"]); +/// let _ = call(&["kill-session", "-t", "muxed-test"]); /// ``` pub fn call(args: &[&str]) -> Result { //println!("{:?}", &args); @@ -35,14 +39,18 @@ pub fn call(args: &[&str]) -> Result { /// Has session is used firgure out if a named session is already running. /// +/// `target`: A string represented by the `{named_session}` +/// /// # Examples /// -/// ``` -/// tmux::has_session("muxed".to_string()); -/// => ExitStatus -/// ``` +/// ```rust +/// extern crate load; +/// use load::tmux; /// -/// `target`: A string represented by the `{named_session}` +/// let session = tmux::has_session("muxed"); +/// +/// assert!(!session.success()); +/// ``` pub fn has_session(target: &str) -> ExitStatus { let output = call(&["has-session", "-t", target]).expect("failed to see if the session existed"); @@ -53,9 +61,11 @@ pub fn has_session(target: &str) -> ExitStatus { /// /// # Examples /// -/// ``` +/// ```rust +/// extern crate load; +/// use load::tmux; +/// /// tmux::get_config(); -/// => "some-option false\npane-base-index 0" /// ``` pub fn get_config() -> String { let output = call(&["start-server", ";", "show-options", "-g", ";", "show-options", "-g", "-w"]) @@ -69,11 +79,14 @@ pub fn get_config() -> String { /// /// # Examples /// -/// ``` -/// let session_name = "muxed".to_string(); -/// tmux::attach(muxed); -/// ``` /// `session_name: The active tmux session name. +/// +/// ```rust,no_run +/// extern crate load; +/// use load::tmux; +/// +/// tmux::attach(&["muxed"]); +/// ``` pub fn attach(args: &[&str]) -> Result { let arg_string = [&[TMUX_NAME], &args[..]].concat().join(" "); let system_call = CString::new(arg_string).unwrap();