mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Initial cargo-read-manifest
This commit is contained in:
parent
fa3fae3662
commit
755aa6d7aa
@ -1,5 +1,51 @@
|
||||
#[crate_id="cargo-read-manifest"];
|
||||
|
||||
fn main() {
|
||||
extern crate hammer;
|
||||
extern crate serialize;
|
||||
extern crate toml;
|
||||
extern crate semver;
|
||||
|
||||
use hammer::{FlagDecoder,FlagConfig,FlagConfiguration};
|
||||
use serialize::{Decoder,Decodable};
|
||||
use serialize::json::Encoder;
|
||||
use toml::from_toml;
|
||||
use semver::Version;
|
||||
|
||||
#[deriving(Decodable,Encodable)]
|
||||
struct Manifest {
|
||||
project: ~Project
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable)]
|
||||
struct Project {
|
||||
name: ~str,
|
||||
version: ~str,
|
||||
authors: ~[~str]
|
||||
}
|
||||
|
||||
#[deriving(Decodable)]
|
||||
struct ReadManifestFlags {
|
||||
manifest_path: ~str
|
||||
}
|
||||
|
||||
impl FlagConfig for ReadManifestFlags {
|
||||
fn config(_: Option<ReadManifestFlags>, c: FlagConfiguration) -> FlagConfiguration {
|
||||
c
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut decoder = FlagDecoder::new::<ReadManifestFlags>(std::os::args().tail());
|
||||
let flags: ReadManifestFlags = Decodable::decode(&mut decoder);
|
||||
|
||||
if decoder.error.is_some() {
|
||||
fail!("Error: {}", decoder.error.unwrap());
|
||||
}
|
||||
|
||||
let root = toml::parse_from_file(flags.manifest_path).unwrap();
|
||||
|
||||
let manifest = from_toml::<Manifest>(root.clone());
|
||||
let encoded: ~str = Encoder::str_encode(&manifest);
|
||||
|
||||
println!("{}", encoded);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4bfa10d99e36ccdf7cb20098d1a520ba1480feb3
|
||||
Subproject commit 06432c54340c21212c1c64f37881605b41378917
|
Loading…
x
Reference in New Issue
Block a user