Skip to content

Commit

Permalink
rustup
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Feb 5, 2015
1 parent 9dd5991 commit d829ec2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 40 deletions.
40 changes: 28 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ opt-level = 2
[dependencies]
csv = "*"
docopt = "*"
rand = "*"
regex = "*"
rustc-serialize = "*"
streaming-stats = "*"
Expand Down
7 changes: 3 additions & 4 deletions src/cmd/sample.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rand::Rng;

use csv::{self, ByteString};
use csv::index::Indexed;
use rand::Rng;

use CliResult;
use config::{Config, Delimiter};
Expand Down Expand Up @@ -81,7 +80,7 @@ fn sample_random_access<R: Reader + Seek, I: Reader + Seek>
(idx: &mut Indexed<R, I>, sample_size: u64)
-> CliResult<Vec<Vec<ByteString>>> {
let mut all_indices = range(0, idx.count()).collect::<Vec<_>>();
let mut rng = ::std::rand::thread_rng();
let mut rng = ::rand::thread_rng();
rng.shuffle(&mut *all_indices);

let mut sampled = Vec::with_capacity(sample_size as usize);
Expand All @@ -105,7 +104,7 @@ fn sample_reservoir<R: Reader>
}

// Now do the sampling.
let mut rng = ::std::rand::thread_rng();
let mut rng = ::rand::thread_rng();
for (i, row) in records {
let random = rng.gen_range(0, i+1);
if random < sample_size as usize {
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::env;
use std::old_io as io;
use std::os;

use rustc_serialize::{Decodable, Decoder};

use csv;
use csv::index::Indexed;
use rustc_serialize::{Decodable, Decoder};

use CliResult;
use select::{SelectColumns, Selection, NormalSelection};
Expand Down Expand Up @@ -90,7 +89,8 @@ impl Config {
}

pub fn no_headers(mut self, mut yes: bool) -> Config {
if os::getenv("XSV_TOGGLE_HEADERS").unwrap_or("0".to_owned()) == "1" {
let toggle = env::var_string("XSV_TOGGLE_HEADERS");
if toggle.unwrap_or("0".to_owned()) == "1" {
yes = !yes;
}
self.no_headers = yes;
Expand Down
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ These are some docs.

#![allow(dead_code, unused_variables)]

#![feature(collections, core, io, os, path, rand, std_misc, unicode)]
#![feature(collections, core, env, io, os, path, std_misc, unicode)]

extern crate csv;
extern crate docopt;
extern crate rand;
extern crate regex;
extern crate "rustc-serialize" as rustc_serialize;
extern crate stats;
extern crate tabwriter;

use std::borrow::ToOwned;
use std::error::FromError;
use std::env;
use std::fmt;
use std::old_io as io;
use std::os;

use docopt::Docopt;

Expand Down Expand Up @@ -89,7 +90,7 @@ fn main() {
}
match args.arg_command {
None => {
os::set_exit_status(0);
env::set_exit_status(0);
let msg = concat!(
"xsv is a suite of CSV command line utilities.
Expand All @@ -99,26 +100,26 @@ Please choose one of the following commands:",
}
Some(cmd) => {
match cmd.run() {
Ok(()) => os::set_exit_status(0),
Ok(()) => env::set_exit_status(0),
Err(CliError::Flag(err)) => err.exit(),
Err(CliError::Csv(err)) => {
os::set_exit_status(1);
env::set_exit_status(1);
io::stderr()
.write_str(&*format!("{}\n", err.to_string()))
.unwrap();
}
Err(CliError::Io(
io::IoError { kind: io::BrokenPipe, .. })) => {
os::set_exit_status(0);
env::set_exit_status(0);
}
Err(CliError::Io(err)) => {
os::set_exit_status(1);
env::set_exit_status(1);
io::stderr()
.write_str(&*format!("{}\n", err.to_string()))
.unwrap();
}
Err(CliError::Other(msg)) => {
os::set_exit_status(1);
env::set_exit_status(1);
io::stderr()
.write_str(&*format!("{}\n", msg))
.unwrap();
Expand Down Expand Up @@ -151,7 +152,8 @@ enum Command {

impl Command {
fn run(self) -> CliResult<()> {
let argv = os::args();
let argv: Vec<_> = env::args()
.map(|v| v.into_string().unwrap()).collect();
let argv: Vec<_> = argv.iter().map(|s| &**s).collect();
let argv = &*argv;
match self {
Expand Down
6 changes: 0 additions & 6 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ pub struct Selection(Vec<usize>);
impl Selection {
pub fn select<'a, 'b>(&'a self, row: &'b [csv::ByteString])
-> iter::Scan<
&'a usize,
&'b [u8],
slice::Iter<'a, usize>,
&'b [csv::ByteString],
for <'c> fn(&mut &'c [csv::ByteString], &usize)
Expand Down Expand Up @@ -387,16 +385,12 @@ impl ops::Deref for Selection {
pub struct NormalSelection(Vec<bool>);

type _NormalScan<'a, T, I> = iter::Scan<
(usize, T),
Option<T>,
iter::Enumerate<I>,
&'a [bool],
fn(&mut &[bool], (usize, T)) -> Option<Option<T>>,
>;

type _NormalFilterMap<'a, T, I> = iter::FilterMap<
Option<T>,
T,
_NormalScan<'a, T, I>,
fn(Option<T>) -> Option<T>
>;
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::{Cow, IntoCow, ToOwned};
use std::error::FromError;
use std::ops::Deref;
use std::path::BytesContainer;
use std::old_path::BytesContainer;
use std::str;

use csv;
Expand Down
5 changes: 3 additions & 2 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#![feature(core, io, os, path, rand, std_misc)]
#![feature(core, env, io, path, std_misc)]

#[macro_use] extern crate log;
extern crate "rustc-serialize" as rustc_serialize;

extern crate csv;
extern crate quickcheck;
extern crate rand;
extern crate stats;

use std::fmt;
use std::iter::range;
use std::mem::transmute;
use std::ops;
use std::rand::{Rng, thread_rng};

use quickcheck::{Arbitrary, Gen, QuickCheck, Shrinker, StdGen, Testable};
use rand::{Rng, thread_rng};

macro_rules! svec[
($($x:expr),*) => (
Expand Down
4 changes: 2 additions & 2 deletions tests/workdir.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use std::fmt;
use std::old_io as io;
use std::old_io::fs::{self, PathExtensions};
use std::old_io::process;
use std::os;
use std::str::FromStr;
use std::sync::atomic;

Expand All @@ -23,7 +23,7 @@ pub struct Workdir {
impl Workdir {
pub fn new(name: &str) -> Workdir {
let id = NEXT_ID.fetch_add(1, atomic::Ordering::SeqCst);
let root = os::self_exe_path().unwrap();
let root = env::current_exe().unwrap().dir_path();
let dir = root.clone()
.join(XSV_INTEGRATION_TEST_DIR)
.join(name)
Expand Down

0 comments on commit d829ec2

Please sign in to comment.