Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new and init command #204

Merged
merged 10 commits into from
Feb 11, 2025
175 changes: 175 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ url = "2.5.2"
uuid = "1.11.0"
wasmtime = "28.0.0"
wasmtime-wasi = "28.0.0"
zip = "2.2.2"

cargo-llvm-cov = "0.6.15"
pretty_assertions = "1.4.1"
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
toml.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
url = { workspace = true, features = ["serde"] }
reqwest = { workspace = true, features = ["blocking"] }
zip.workspace = true

edgee-api-client.workspace = true
edgee-server.workspace = true
edgee-components-runtime.workspace = true

[features]
bundled = [
"openssl/vendored",
]
bundled = ["openssl/vendored"]
64 changes: 64 additions & 0 deletions crates/cli/src/commands/components/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
use crate::components::{
boilerplate::{CATEGORY_OPTIONS, LANGUAGE_OPTIONS, SUBCATEGORY_OPTIONS},
manifest::{self, Build, Manifest, Package},
};

#[derive(Debug, clap::Parser)]
pub struct Options {}

pub async fn run(_opts: Options) -> anyhow::Result<()> {
use inquire::{Select, Text};
if manifest::find_manifest_path().is_some() {
anyhow::bail!("Manifest already exists");
}

let component_name = Text::new("Enter the name of the component:")
.with_validator(inquire::required!("Component name cannot be empty"))
.with_validator(inquire::min_length!(
3,
"Component name must be at least 3 characters"
))
.prompt()?;

let component_language = Select::new(
"Select the language of the component:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment about the future: at some point we will have multiple types of components, so do we expect to have different templates based on language+type or can we just keep 1 boilerplace repo per language that includes all types?

if we go with multiple repos based on language+types, here we will need to select the language/type combo (or maybe an additional step to select the type, and then the language).

If we go for just language selection, this is already OK 👌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd still need to have a subcategory selection for the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it following Jill changes to include it in manifest

LANGUAGE_OPTIONS.to_vec(),
)
.prompt()?;
let component_category = if CATEGORY_OPTIONS.len() == 1 {
CATEGORY_OPTIONS[0].clone() // Accès direct car on sait qu'il y a un seul élément
} else {
Select::new(
"Select the category of the component:",
CATEGORY_OPTIONS.to_vec(), // Pas besoin de `.to_vec()`, on passe une slice
)
.prompt()?
};

let component_subcategory = Select::new(
"Select the language of the component:",
SUBCATEGORY_OPTIONS.to_vec(),
)
.prompt()?;

println!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KokaKiwi is there any crates for printing that you might recommand ?

"Initiating component {} in {}",
component_name, component_language.name
);

Manifest {
manifest_version: manifest::MANIFEST_VERSION,
package: Package {
name: component_name,
version: "0.1.0".to_string(),
wit_world_version: "0.4.0".to_string(),
category: *component_category.value,
subcategory: *component_subcategory.value,
description: None,
documentation: None,
repository: None,
config_fields: Default::default(),
build: Build {
command: component_language.default_build_command.to_string(),
output_path: std::path::PathBuf::from(""),
},
},
}
.save(std::path::Path::new("./"))?;

Ok(())
}
Loading