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
extern crate sysadmin; | |
use sysadmin::{file}; | |
// Use docopt.rs to generate the cli arguments, process ARGV, | |
// and set up a main() that runs the run function. Checks the | |
// results and runs at_exit with nice error messages and a variety | |
// of error codes | |
cli!( | |
"Usage: wc [--lines] <file> |
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
use rustc_serialize::Encodable; | |
use toml; | |
#[derive(RustcEncodable, Clone)] | |
pub struct Config { | |
pub server: Option<String>, | |
pub user: Option<String>, | |
pub enterprise: Option<String>, | |
pub organization: Option<String>, | |
pub project: Option<String>, |
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
struct Config { | |
server: Option<String>, | |
user: Option<String> | |
} | |
impl Config { | |
get(&self, key: &str) -> Result<String, Error> { | |
match self.get(key) { | |
Some(v) => return Ok(v), | |
None => Err(Error{kind: Kind::MissingValue, description: Some(format!("Missing value for {}", key))}) |
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
Compiling delivery v0.0.1 (file:///Users/adam/src/opscode/delivery/opscode/delivery-cli) | |
/Users/adam/src/opscode/delivery/opscode/delivery-cli/src/utils/say.rs:11:12: 11:25 error: wrong number of lifetime parameters: expected 1, found 0 [E0107] | |
/Users/adam/src/opscode/delivery/opscode/delivery-cli/src/utils/say.rs:11 guard: JoinGuard<()> | |
^~~~~~~~~~~~~ | |
error: aborting due to previous error | |
Could not compile `delivery`. | |
To learn more, run the command again with --verbose. |
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
#![feature(plugin)] | |
extern crate regex; | |
#[plugin] extern crate regex_macros; | |
extern crate "rustc-serialize" as rustc_serialize; | |
#[macro_use] extern crate docopt; | |
#[plugin] extern crate docopt_macros; | |
#[macro_use] extern crate log; |
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
#![feature(phase)] | |
#![feature(old_orphan_check)] | |
extern crate regex; | |
#[macro_use] extern crate regex_macros; | |
extern crate "rustc-serialize" as rustc_serialize; | |
extern crate docopt; | |
#[macro_use] extern crate docopt_macros; | |
#[macro_use] extern crate log; | |
use std::os; |
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
extern crate chef; | |
use chef::{client}; | |
use chef::resource::{Package, Service, Template}; | |
// Total Strawman | |
fn main() { | |
let mut chef = client.new(); | |
chef.r( | |
Package{ |
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
fn current_branch(path: &Path) -> String { | |
let head_ref = head_ref(path); | |
println!("The ref for HEAD is {}", head_ref); | |
let r = regex!(r"refs/heads/(.+)"); | |
let caps_result = r.captures(head_ref.as_slice()); | |
let branch: String = match caps_result { | |
Some(cap) => { String::from_str(cap.at(1)) }, | |
None => { panic!("You must be somewhere on refs/heads, and you aren't") } | |
}; | |
branch |
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
func current_branch(git_dir string) string { | |
head_bytes, err := ioutil.ReadFile(path.Join(git_dir, "HEAD")) | |
head := string(head_bytes) | |
if err != nil { | |
log.Fatal("Cannot open HEAD from ", git_dir) | |
} | |
r, _ := regexp.Compile("ref: ref/heads/(.+)") | |
match := r.FindStringSubmatch(head) | |
branch := match[1] | |
return branch |
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
func dot_git_dir(dir string) string { | |
git_dir := path.Join(dir, ".git") | |
_, dir_error := os.Stat(git_dir) | |
if dir_error != nil { | |
if git_dir == "/.git" { | |
log.Fatal("Cannot find a .git directory") | |
} | |
return dot_git_dir(path.Dir(dir)) | |
} else { | |
return git_dir |