-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "edit" | ||
version = "0.7.2-development" | ||
authors = ["Brian Pearce"] | ||
publish = false | ||
|
||
[lib] | ||
doctest = false | ||
|
||
[dependencies] | ||
common = { path = "../common" } | ||
dirs = "1.0.5" | ||
libc = "0.2.21" | ||
|
||
[dev-dependencies] | ||
rand = "0.3.15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Muxednew. A Muxed project Template Generator | ||
extern crate common; | ||
extern crate dirs; | ||
extern crate libc; | ||
#[cfg(test)] | ||
extern crate rand; | ||
|
||
use common::args::Args; | ||
|
||
#[cfg(not(test))] | ||
use dirs::home_dir; | ||
use libc::system; | ||
#[cfg(test)] | ||
use rand::random; | ||
use std::ffi::CString; | ||
#[cfg(test)] | ||
use std::fs; | ||
use std::io; | ||
use std::path::PathBuf; | ||
|
||
static MUXED_FOLDER: &str = "muxed"; | ||
|
||
pub fn exec(args: Args) -> Result<(), io::Error> { | ||
let home = homedir().expect("Can't find home dir"); | ||
let default_dir = format!("{}/.{}", home.display(), MUXED_FOLDER); | ||
let project_name = format!("{}.yml", &args.arg_project); | ||
let muxed_dir = match args.flag_p { | ||
Some(ref x) => x.as_str(), | ||
_ => default_dir.as_str(), | ||
}; | ||
|
||
let command = format!("{} {}/{}", "$EDITOR", muxed_dir, project_name); | ||
let system_call = CString::new(command).unwrap(); | ||
|
||
unsafe { | ||
system(system_call.as_ptr()); | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Return the users homedir as a string. | ||
#[cfg(not(test))] | ||
fn homedir() -> Result<PathBuf, String> { | ||
match home_dir() { | ||
Some(dir) => Ok(dir), | ||
None => Err(String::from("We couldn't find your home directory.")), | ||
} | ||
} | ||
|
||
/// Return the temp dir as the users home dir during testing. | ||
#[cfg(test)] | ||
fn homedir() -> Result<PathBuf, String> { | ||
Ok(PathBuf::from("/tmp")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! The integration suite for inspecting sessions. | ||
extern crate common; | ||
extern crate new; | ||
extern crate rand; | ||
|
||
#[cfg(test)] | ||
mod test { | ||
mod new { | ||
use common::args::Args; | ||
use new; | ||
use rand::random; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
pub fn new(project: &str, project_root: &PathBuf) -> Result<(), String> { | ||
let args = Args { | ||
flag_debug: false, | ||
flag_dryrun: false, | ||
flag_d: true, | ||
flag_v: false, | ||
flag_f: false, | ||
flag_p: Some(format!("{}", project_root.display())), | ||
flag_t: None, | ||
arg_project: project.to_string(), | ||
cmd_new: false, | ||
cmd_snapshot: false, | ||
}; | ||
|
||
new::exec(args) | ||
} | ||
|
||
fn setup(project_name: &str) -> (PathBuf, PathBuf) { | ||
let project_file = format!("/tmp/muxed_{}/{}.yml", random::<u16>(), project_name); | ||
let project_path = PathBuf::from(&project_file); | ||
|
||
let m = project_path.clone(); | ||
let muxed_path = project_path.parent().unwrap(); | ||
(m, muxed_path.to_path_buf()) | ||
} | ||
|
||
fn cleanup(config_path: &PathBuf) { | ||
let _ = fs::remove_file(config_path); | ||
let _ = fs::remove_dir(config_path.parent().unwrap()); | ||
} | ||
|
||
#[test] | ||
fn creates_new_file_muxed() { | ||
let project_name = format!("muxed_int_test_{}", random::<u16>()); | ||
let (project_path, muxed_path) = setup(&project_name); | ||
let _ = new(&project_name, &muxed_path); | ||
assert!(&project_path.exists()); | ||
cleanup(&project_path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters