@@ -27,13 +27,12 @@ extern mod syntax(vers = "0.6");
27
27
28
28
use core::*;
29
29
use io::{ReaderUtil, WriterUtil};
30
- use std::getopts;
30
+ use std::{json, semver, getopts} ;
31
31
use std::net::url;
32
32
use send_map::linear::LinearMap;
33
33
use rustc::metadata::filesearch;
34
34
use rustc::driver::{driver, session};
35
35
use syntax::{ast, attr, codemap, diagnostic, parse, visit};
36
- use std::semver;
37
36
38
37
mod usage;
39
38
mod util;
@@ -251,6 +250,7 @@ impl PackageScript {
251
250
252
251
struct Ctx {
253
252
cfgs: ~[~str],
253
+ json: bool,
254
254
mut dep_cache: LinearMap<~str, bool>
255
255
}
256
256
@@ -294,6 +294,9 @@ impl Ctx {
294
294
295
295
self.do_cmd(args[0]);
296
296
}
297
+ ~"info" => {
298
+ self.info();
299
+ }
297
300
~"install" => {
298
301
self.install(if args.len() >= 1 { Some(args[0]) }
299
302
else { None },
@@ -470,6 +473,58 @@ impl Ctx {
470
473
true
471
474
}
472
475
476
+ fn info() {
477
+ if self.json {
478
+ match PackageScript::parse(&os::getcwd()) {
479
+ result::Ok(script) => {
480
+ let mut map = ~LinearMap();
481
+
482
+ map.insert(~"id", json::String(script.id));
483
+ map.insert(~"name", json::String(script.name));
484
+ map.insert(~"vers", json::String(script.vers.to_str()));
485
+ map.insert(~"deps", json::List(do script.deps.map |&dep| {
486
+ let (url, target) = dep;
487
+ let mut inner = ~LinearMap();
488
+
489
+ inner.insert(~"url", json::String(url));
490
+
491
+ if !target.is_none() {
492
+ inner.insert(~"target", json::String(target.get()));
493
+ }
494
+
495
+ json::Object(inner)
496
+ }));
497
+
498
+ io::println(json::to_pretty_str(&json::Object(map)));
499
+ }
500
+ result::Err(_) => io::println(~"{}")
501
+ }
502
+ } else {
503
+ let script = match PackageScript::parse(&os::getcwd()) {
504
+ result::Ok(script) => script,
505
+ result::Err(err) => {
506
+ util::error(err);
507
+
508
+ return;
509
+ }
510
+ };
511
+
512
+ util::note(fmt!("id: %s", script.id));
513
+ util::note(fmt!("name: %s", script.name));
514
+ util::note(fmt!("vers: %s", script.vers.to_str()));
515
+ util::note(fmt!("deps: %s", if script.deps.len() > 0 { ~"" } else { ~"none" }));
516
+
517
+ for script.deps.each |&dep| {
518
+ let (url, target) = dep;
519
+
520
+ util::note(fmt!(" <%s> (%s)", url, match target {
521
+ Some(target) => target,
522
+ None => ~""
523
+ }));
524
+ }
525
+ }
526
+ }
527
+
473
528
fn install(url: Option<~str>, target: Option<~str>, cache: bool) -> bool {
474
529
let mut success;
475
530
let mut dir;
@@ -783,6 +838,7 @@ impl Ctx {
783
838
pub fn main() {
784
839
let args = os::args();
785
840
let opts = ~[getopts::optflag(~"h"), getopts::optflag(~"help"),
841
+ getopts::optflag(~"j"), getopts::optflag(~"json"),
786
842
getopts::optmulti(~"c"), getopts::optmulti(~"cfg")];
787
843
let matches = &match getopts::getopts(args, opts) {
788
844
result::Ok(m) => m,
@@ -794,6 +850,8 @@ pub fn main() {
794
850
};
795
851
let help = getopts::opt_present(matches, ~"h") ||
796
852
getopts::opt_present(matches, ~"help");
853
+ let json = getopts::opt_present(matches, ~"j") ||
854
+ getopts::opt_present(matches, ~"json");
797
855
let cfgs = vec::append(getopts::opt_strs(matches, ~"cfg"),
798
856
getopts::opt_strs(matches, ~"c"));
799
857
let mut args = copy matches.free;
@@ -813,6 +871,7 @@ pub fn main() {
813
871
~"build" => usage::build(),
814
872
~"clean" => usage::clean(),
815
873
~"do" => usage::do_cmd(),
874
+ ~"info" => usage::info(),
816
875
~"install" => usage::install(),
817
876
~"prefer" => usage::prefer(),
818
877
~"test" => usage::test(),
@@ -824,6 +883,7 @@ pub fn main() {
824
883
825
884
Ctx {
826
885
cfgs: cfgs,
886
+ json: json,
827
887
mut dep_cache: LinearMap()
828
888
}.run(cmd, args);
829
889
}
@@ -906,7 +966,7 @@ pub fn Crate(file: ~str) -> Crate {
906
966
* Assumes that the package script has been compiled
907
967
* in is the working directory.
908
968
*/
909
- fn work_dir() -> Path {
969
+ pub fn work_dir() -> Path {
910
970
os::self_exe_path().get()
911
971
}
912
972
@@ -916,7 +976,7 @@ fn work_dir() -> Path {
916
976
* that the cwd is changed to it before
917
977
* running this executable.
918
978
*/
919
- fn src_dir() -> Path {
979
+ pub fn src_dir() -> Path {
920
980
os::getcwd()
921
981
}
922
982
0 commit comments