Skip to content

Commit 023aab4

Browse files
committed
auto merge of #9236 : steveklabnik/rust/rustpkg_init, r=catamorphism
Closes #9045 Built on top of #9235, which isn't strictly needed for now, but I imagine I will use part of. Unsure. I mostly wanted to start this off to get some feedback from @catamorphism and others. These are the directories that actually need made, but I was thinking about adding a few other things: 1. an `examples` directory, since it seems like that's a common pattern 2. a `.gitignore` file that ignores `build`. And anything else that makes sense 3. a sample module that'd actually compile Feedback?
2 parents 72e7c62 + 77bbf23 commit 023aab4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/librustpkg/rustpkg.rs

+16
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub trait CtxMethods {
189189
fn test(&self);
190190
fn uninstall(&self, _id: &str, _vers: Option<~str>);
191191
fn unprefer(&self, _id: &str, _vers: Option<~str>);
192+
fn init(&self);
192193
}
193194

194195
impl CtxMethods for BuildContext {
@@ -319,6 +320,13 @@ impl CtxMethods for BuildContext {
319320
"test" => {
320321
self.test();
321322
}
323+
"init" => {
324+
if args.len() != 0 {
325+
return usage::init();
326+
} else {
327+
self.init();
328+
}
329+
}
322330
"uninstall" => {
323331
if args.len() < 1 {
324332
return usage::uninstall();
@@ -540,6 +548,13 @@ impl CtxMethods for BuildContext {
540548
fail!("test not yet implemented");
541549
}
542550

551+
fn init(&self) {
552+
os::mkdir_recursive(&Path("src"), U_RWX);
553+
os::mkdir_recursive(&Path("lib"), U_RWX);
554+
os::mkdir_recursive(&Path("bin"), U_RWX);
555+
os::mkdir_recursive(&Path("build"), U_RWX);
556+
}
557+
543558
fn uninstall(&self, _id: &str, _vers: Option<~str>) {
544559
fail!("uninstall not yet implemented");
545560
}
@@ -688,6 +703,7 @@ pub fn main_args(args: &[~str]) {
688703
~"list" => usage::list(),
689704
~"prefer" => usage::prefer(),
690705
~"test" => usage::test(),
706+
~"init" => usage::init(),
691707
~"uninstall" => usage::uninstall(),
692708
~"unprefer" => usage::unprefer(),
693709
_ => usage::general()

src/librustpkg/usage.rs

+7
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ and exit code will be redirected.
148148
Options:
149149
-c, --cfg Pass a cfg flag to the package script");
150150
}
151+
152+
pub fn init() {
153+
io::println("rustpkg init name
154+
155+
This makes a new workspace for working on a project named name.
156+
");
157+
}

src/librustpkg/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use workcache_support::{digest_file_with_date, digest_only_date};
3333
// you could update the match in rustpkg.rc but forget to update this list. I think
3434
// that should be fixed.
3535
static COMMANDS: &'static [&'static str] =
36-
&["build", "clean", "do", "info", "install", "list", "prefer", "test", "uninstall",
36+
&["build", "clean", "do", "info", "init", "install", "list", "prefer", "test", "uninstall",
3737
"unprefer"];
3838

3939

0 commit comments

Comments
 (0)