use std::fmt;
-use core::NameVer;
+use core::{NameVer,Package};
use CargoResult;
-#[deriving(Clone,Eq)]
-pub struct PackagePath {
- name: NameVer,
- path: Path
-}
-
-impl fmt::Show for PackagePath {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f.buf, "{} at {}", self.name, self.path.display())
- }
-}
-
-impl PackagePath {
- pub fn new(name: NameVer, path: Path) -> PackagePath {
- PackagePath { name: name, path: path }
- }
-}
-
/**
* A Source finds and downloads remote packages based on names and
* versions.
* The download method fetches the full package for each name and
* version specified.
*/
- fn download(&self, packages: Vec<NameVer>) -> CargoResult<()>;
+ fn download(&self, packages: &[NameVer]) -> CargoResult<()>;
/**
* The get method returns the Path of each specified package on the
* and that the packages are already locally available on the file
* system.
*/
- fn get(&self, packages: Vec<NameVer>) -> CargoResult<Vec<PackagePath>>;
+ fn get(&self, packages: Vec<NameVer>) -> CargoResult<Vec<Package>>;
}
use util::config::{all_configs,ConfigValue};
use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
use core::Package;
+use core::source::Source;
+use sources::path::PathSource;
use {CargoError,ToCargoError,CargoResult};
#[deriving(Decodable)]
let paths = match config_paths.get_value() {
&config::String(_) => return Err(CargoError::new(~"The path was configured as a String instead of a List", 1)),
- &config::List(ref list) => list
+ &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
};
- println!("Paths: {}: {}", paths.len(), paths);
-
- let packages: Vec<Package> = paths.iter().filter_map(|path| {
- let joined = Path::new(path.as_slice()).join("Cargo.toml");
- let manifest = cargo_read_manifest(joined.as_str().unwrap());
-
- match manifest {
- Ok(ref manifest) => Some(Package::from_manifest(manifest)),
- Err(_) => None
- }
- }).collect();
+ let source = PathSource::new(paths);
+ let names = try!(source.list());
+ try!(source.download(names.as_slice()));
+ let packages = try!(source.get(names));
println!("Packages: {}", packages);
Ok(())
-mod path;
+pub mod path;
-use core::source::{Source,PackagePath};
-use core::NameVer;
+use core::{NameVer,Package};
+use core::source::Source;
+use core::manifest::Manifest;
use CargoResult;
-use ops::cargo_read_manifest::read_manifest;
+use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
-struct PathSource {
+pub struct PathSource {
paths: Vec<Path>
}
fn update(&self) -> CargoResult<()> { Ok(()) }
fn list(&self) -> CargoResult<Vec<NameVer>> {
- self.map(|path| {
- let manifest = try!(read_manifest(path.as_str().unwrap()));
- Ok(manifest.get_name_ver())
- })
+ Ok(self.paths.iter().filter_map(|path| {
+ match read_manifest(path) {
+ Ok(ref manifest) => Some(manifest.get_name_ver()),
+ Err(_) => None
+ }
+ }).collect())
}
- fn download(&self, name_ver: Vec<NameVer>) -> CargoResult<()>{
+ fn download(&self, name_ver: &[NameVer]) -> CargoResult<()>{
Ok(())
}
- fn get(&self, packages: Vec<NameVer>) -> CargoResult<Vec<PackagePath>> {
- self.map(|path| {
- let manifest = try!(read_manifest(path.as_str().unwrap()));
- let name_ver = manifest.get_name_ver();
- let path = manifest.get_path();
-
- Ok(PackagePath::new(name_ver, path))
- })
+ fn get(&self, packages: Vec<NameVer>) -> CargoResult<Vec<Package>> {
+ Ok(self.paths.iter().filter_map(|path| {
+ match read_manifest(path) {
+ Ok(ref manifest) => Some(Package::from_manifest(manifest)),
+ Err(_) => None
+ }
+ }).collect())
}
}
+
+fn read_manifest(path: &Path) -> CargoResult<Manifest> {
+ let joined = path.join("Cargo.toml");
+ cargo_read_manifest(joined.as_str().unwrap())
+}