-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding the option to choose starter template
- Loading branch information
1 parent
9e90b95
commit 22f7450
Showing
7 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
pub mod generate; | ||
pub mod template; | ||
|
||
#[derive(Debug)] | ||
pub struct CmdExit { | ||
pub code: i32, | ||
pub message: Option<String>, | ||
} | ||
|
||
impl CmdExit { | ||
#[must_use] | ||
pub fn error_with_message(message: &str) -> Self { | ||
Self { | ||
code: 1, | ||
message: Some(message.to_string()), | ||
} | ||
} | ||
#[must_use] | ||
pub fn ok_with_message(message: &str) -> Self { | ||
Self { | ||
code: 0, | ||
message: Some(message.to_string()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::str::FromStr; | ||
|
||
use dialoguer::{theme::ColorfulTheme, Select}; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use serde_variant::to_variant_name; | ||
use strum::{EnumIter, EnumString, IntoEnumIterator}; | ||
|
||
#[derive(clap::ValueEnum, Clone, Serialize, Deserialize, Debug, EnumIter, EnumString)] | ||
pub enum Starter { | ||
#[serde(rename = "Saas")] | ||
#[strum(serialize = "Saas")] | ||
Saas, | ||
#[serde(rename = "Stateless (not db)")] | ||
#[strum(serialize = "Stateless (not db)")] | ||
Stateless, | ||
} | ||
|
||
impl std::fmt::Display for Starter { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
to_variant_name(self).expect("only enum supported").fmt(f) | ||
} | ||
} | ||
|
||
impl Starter { | ||
#[must_use] | ||
pub fn to_list() -> Vec<String> { | ||
Self::iter().map(|provider| provider.to_string()).collect() | ||
} | ||
|
||
/// Show interactive starter selection | ||
/// | ||
/// # Errors | ||
/// When could not show the prompt or could not convert selection the | ||
/// [`Starter`] | ||
pub fn prompt_selection() -> eyre::Result<Self> { | ||
let selections = Self::to_list(); | ||
let selection = Select::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Choose starter template") | ||
.default(0) | ||
.items(&selections[..]) | ||
.interact()?; | ||
|
||
println!("{}", &selections[selection]); | ||
Ok(Self::from_str(&selections[selection])?) | ||
} | ||
|
||
#[must_use] | ||
pub fn git_url(&self) -> String { | ||
match self { | ||
Self::Saas => { | ||
"https://github.com/rustyrails-rs/rustyrails-starter-template".to_string() | ||
} | ||
Self::Stateless => { | ||
"https://github.com/rustyrails-rs/rustyrails-starter-without-db-template" | ||
.to_string() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters