Skip to content

Commit

Permalink
feat(name): add projectname struct for casing variants
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Jul 27, 2018
1 parent 807b8df commit a2320b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
9 changes: 0 additions & 9 deletions src/interactive.rs
@@ -1,7 +1,6 @@
use console::style;
use dialoguer::Input;
use emoji;
use heck::KebabCase;
use quicli::prelude::Error;
use regex;

Expand All @@ -14,14 +13,6 @@ pub fn name() -> Result<String, Error> {
style("Project Name").bold()
)).interact()?;
if valid_ident.is_match(&name) {

println!(
"{} {} `{}`{}",
emoji::WRENCH,
style("Creating project called").bold(),
style(&name.to_kebab_case()).bold().yellow(),
style("...").bold()
);
break name;
} else {
eprintln!(
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Expand Up @@ -15,9 +15,11 @@ mod emoji;
mod git;
mod interactive;
mod progressbar;
mod projectname;
mod template;

use console::style;
use projectname::ProjectName;
use quicli::prelude::*;
use std::env;

Expand Down Expand Up @@ -58,13 +60,21 @@ pub struct Args {
main!(|_cli: Cli| {
let Cli::Generate(args) = Cli::from_args();
let name = match &args.name {
Some(ref n) => n.to_string(),
None => interactive::name()?,
Some(ref n) => ProjectName::new(n),
None => ProjectName::new(&interactive::name()?),
};

println!(
"{} {} `{}`{}",
emoji::WRENCH,
style("Creating project called").bold(),
style(&name.kebab_case).bold().yellow(),
style("...").bold()
);

let project_dir = env::current_dir()
.unwrap_or_else(|_e| ".".into())
.join(&name);
.join(&name.kebab_case);

ensure!(
!project_dir.exists(),
Expand All @@ -75,7 +85,7 @@ main!(|_cli: Cli| {
git::create(&project_dir, args)?;
git::remove_history(&project_dir)?;

let template = template::substitute(&name)?;
let template = template::substitute(&name.kebab_case)?;

let pbar = progressbar::new();
pbar.tick();
Expand Down
15 changes: 15 additions & 0 deletions src/projectname.rs
@@ -0,0 +1,15 @@
use heck::{KebabCase, SnakeCase};

pub struct ProjectName {
pub kebab_case: String,
pub snake_case: String,
}

impl ProjectName {
pub fn new(name: &str) -> ProjectName {
ProjectName {
kebab_case: name.to_kebab_case(),
snake_case: name.to_snake_case(),
}
}
}

0 comments on commit a2320b5

Please sign in to comment.