Skip to content

Commit

Permalink
feat: add new and init command (#204)
Browse files Browse the repository at this point in the history
* feat: add new and init command

* feat: update commands

* feat: fix clippy

* feat: added default build command for the init

* feat: update manifest for init with new cattegory and subcat prompt

* feat: updated some typos and added logs

* feat: add instructions to install dependencies

* feat: update command with new manifest

* add TypeScript to components boilerplace

---------

Co-authored-by: Alex Casalboni <alexsaxmib@gmail.com>
  • Loading branch information
NicolasGirardot and alexcasalboni authored Feb 11, 2025
1 parent d9d1fe3 commit 2b1910d
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 11 deletions.
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:",
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!(
"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

0 comments on commit 2b1910d

Please sign in to comment.