Skip to content

Commit 38d7557

Browse files
authored
feat: add interactivity to create subcommand using inquire crate (#45)
* feat: added interactive metassr create subcommand using inquire crate * remove metacall-sys
1 parent 26ff639 commit 38d7557

File tree

6 files changed

+235
-21
lines changed

6 files changed

+235
-21
lines changed

Cargo.lock

Lines changed: 182 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ nu-ansi-term = "0.50.0"
2020
walkdir = "2.5.0"
2121
serde_json = "1.0.120"
2222
lazy_static = "1.5.0"
23+
inquire = "0.9.1"
2324

2425
axum = "0.7.5"
2526
tokio = { version = "1.36.0", features = ["full"] }

metassr-cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
[dependencies]
99
anyhow = "1.0.82"
1010
clap = { version = "4.5.4", features = ["derive"] }
11+
inquire = "0.9.1"
1112
metacall = "0.5.1"
1213

1314
axum = "0.7.5"
@@ -19,4 +20,4 @@ tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
1920
logger = { path = "../crates/logger" }
2021
metassr-server = { path = "../crates/metassr-server" }
2122
metassr-build = { path = "../crates/metassr-build" }
22-
metassr-create = { path = "../crates/metassr-create" }
23+
metassr-create = { path = "../crates/metassr-create" }

metassr-cli/src/cli/creator.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::ValueEnum;
2+
use inquire;
23
use metassr_create::Creator as MetassrCreator;
34
use std::{fmt::Display, str::FromStr};
45
use tracing::{error, info};
@@ -14,17 +15,51 @@ pub struct Creator {
1415

1516
impl Creator {
1617
pub fn new(
17-
project_name: String,
18-
version: String,
19-
description: String,
20-
template: Template,
21-
) -> Self {
22-
Self {
18+
project_name: Option<String>,
19+
version: Option<String>,
20+
description: Option<String>,
21+
template: Option<Template>,
22+
) -> anyhow::Result<Self> {
23+
let project_name = match project_name {
24+
Some(name) => name,
25+
None => inquire::Text::new("Project name:")
26+
.with_help_message("Enter the name of your new project")
27+
.prompt()?,
28+
};
29+
30+
let template = match template {
31+
Some(template) => template,
32+
None => {
33+
let options = vec![Template::Javascript, Template::Typescript];
34+
inquire::Select::new("Template:", options)
35+
.with_help_message("Choose a template for your new project")
36+
.with_starting_cursor(0)
37+
.prompt()?
38+
}
39+
};
40+
41+
let version = match version {
42+
Some(version) => version,
43+
None => inquire::Text::new("Version:")
44+
.with_help_message("Enter the version of your application")
45+
.with_default("1.0.0")
46+
.prompt()?,
47+
};
48+
49+
let description = match description {
50+
Some(desc) => desc,
51+
None => inquire::Text::new("Description:")
52+
.with_default("A web application built with MetaSSR framework")
53+
.with_help_message("Enter a brief description of your application")
54+
.prompt()?,
55+
};
56+
57+
Ok(Self {
2358
project_name,
2459
version,
2560
description,
2661
template,
27-
}
62+
})
2863
}
2964
}
3065

metassr-cli/src/cli/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ pub enum Commands {
7272
Create {
7373
/// The name of the new project. This is a required argument.
7474
#[arg(index = 1)]
75-
project_name: String,
75+
project_name: Option<String>,
7676

7777
/// The version of your web application.
78-
#[arg(long, short, default_value_t = String::from("1.0.0"))]
79-
version: String,
78+
#[arg(long, short)]
79+
version: Option<String>,
8080

8181
/// A brief description of your web application.
82-
#[arg(long, short, default_value_t = String::from("A web application built with MetaSSR framework"))]
83-
description: String,
82+
#[arg(long, short)]
83+
description: Option<String>,
8484

8585
/// The template to use for creating the new project.
86-
#[arg(long, short, default_value_t = Template::Javascript)]
87-
template: Template,
86+
#[arg(long, short)]
87+
template: Option<Template>,
8888
},
8989
}

0 commit comments

Comments
 (0)