Skip to content

Commit 6099da4

Browse files
committed
Added command to dump templates.
1 parent 5384ee7 commit 6099da4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/templates.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ lazy_static! {
2727

2828
#[derive(Debug)]
2929
pub enum Args {
30+
Dump { name: String },
3031
List,
3132
Show { path: bool },
3233
}
@@ -39,6 +40,16 @@ impl Args {
3940
.about("Manage Cargo Script expression templates.")
4041
.setting(AppSettings::SubcommandRequiredElseHelp)
4142

43+
.subcommand(SubCommand::with_name("dump")
44+
.about("Outputs the contents of a template to standard output.")
45+
46+
.arg(Arg::with_name("template")
47+
.help("Name of template to dump.")
48+
.index(1)
49+
.required(true)
50+
)
51+
)
52+
4253
.subcommand(SubCommand::with_name("list")
4354
.about("List the available templates.")
4455
)
@@ -55,6 +66,11 @@ impl Args {
5566

5667
pub fn parse(m: &clap::ArgMatches) -> Self {
5768
match m.subcommand() {
69+
("dump", Some(m)) => {
70+
Args::Dump {
71+
name: m.value_of("template").unwrap().into(),
72+
}
73+
},
5874
("list", _) => Args::List,
5975
("show", Some(m)) => {
6076
Args::Show {
@@ -68,6 +84,7 @@ impl Args {
6884

6985
pub fn try_main(args: Args) -> Result<i32> {
7086
match args {
87+
Args::Dump { name } => try!(dump(&name)),
7188
Args::List => try!(list()),
7289
Args::Show { path } => try!(show(path)),
7390
}
@@ -161,6 +178,12 @@ fn builtin_template(name: &str) -> Option<&'static str> {
161178
})
162179
}
163180

181+
fn dump(name: &str) -> Result<()> {
182+
let text = try!(get_template(name));
183+
print!("{}", text);
184+
Ok(())
185+
}
186+
164187
fn list() -> Result<()> {
165188
use std::ffi::OsStr;
166189

0 commit comments

Comments
 (0)