Skip to content

Commit

Permalink
push: sluggify name
Browse files Browse the repository at this point in the history
  • Loading branch information
CLEMENTINATOR committed Feb 13, 2025
1 parent 90e05a5 commit f2b53aa
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/cli/src/commands/components/push.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::components::manifest::Manifest;
use edgee_api_client::types as api_types;

use slug;
#[derive(Debug, clap::Parser)]
pub struct Options {
/// The organization name used to create or update your component
Expand Down Expand Up @@ -41,11 +41,11 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
.api_context("Could not get user organization")?
.into_inner(),
};

let component_slug = slug::slugify(&manifest.package.name);
match client
.get_component_by_slug()
.org_slug(&organization.slug)
.component_slug(&manifest.package.name)
.component_slug(&component_slug)
.send()
.await
{
Expand All @@ -56,7 +56,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
tracing::info!("Component does not exist, creating...");
let confirm = Confirm::new(&format!(
"Component `{}/{}` does not exists, do you want to create it?",
organization.slug, manifest.package.name,
organization.slug, &component_slug,
))
.with_default(true)
.prompt()?;
Expand All @@ -76,6 +76,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
api_types::ComponentCreateInput::builder()
.organization_id(organization.id.clone())
.name(&manifest.package.name)
.slug(component_slug.clone())
.description(manifest.package.description.clone())
.category(manifest.package.category)
.subcategory(manifest.package.subcategory)
Expand All @@ -101,7 +102,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
tracing::info!(
"Component `{}/{}` created successfully!",
organization.slug,
manifest.package.name
component_slug
);
}
Ok(_) | Err(_) => {}
Expand All @@ -112,7 +113,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {

let confirm = Confirm::new(&format!(
"Please confirm to push the component `{}/{}`:",
organization.slug, manifest.package.name,
organization.slug, component_slug,
))
.with_default(true)
.prompt()?;
Expand All @@ -130,7 +131,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
client
.create_component_version_by_slug()
.org_slug(organization.slug)
.component_slug(&manifest.package.name)
.component_slug(&component_slug)
.body(
api_types::ComponentVersionCreateInput::builder()
.version(&manifest.package.version)
Expand All @@ -145,7 +146,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {

tracing::info!(
"{} {} pushed successfully!",
manifest.package.name,
component_slug,
manifest.package.version
);

Expand Down

0 comments on commit f2b53aa

Please sign in to comment.