Skip to content

Commit 3ff81f3

Browse files
committed
component push: add --public/private flags
1 parent d3fa9f8 commit 3ff81f3

File tree

1 file changed

+57
-6
lines changed
  • crates/cli/src/commands/components

1 file changed

+57
-6
lines changed

crates/cli/src/commands/components/push.rs

+57-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Options {
1212
///
1313
/// Defaults to the user "self" org
1414
pub organization: Option<String>,
15+
1516
#[arg(long, conflicts_with = "private")]
1617
pub public: bool,
1718

@@ -118,11 +119,18 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
118119
return Ok(());
119120
}
120121

121-
let public_or_private = Select::new(
122-
"Would you like to make this component public or private?",
123-
vec!["private", "public"],
124-
)
125-
.prompt()?;
122+
let public = match (opts.public, opts.private) {
123+
(true, false) => true,
124+
(false, true) => false,
125+
_ => {
126+
Select::new(
127+
"Would you like to make this component public or private?",
128+
vec!["private", "public"],
129+
)
130+
.prompt()?
131+
== "public"
132+
}
133+
};
126134

127135
let avatar_url = if let Some(path) = &manifest.component.icon_path {
128136
tracing::info!("Uploading Icon... {:?}", manifest.component.icon_path);
@@ -156,7 +164,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
156164
.map(|url| url.to_string()),
157165
)
158166
.avatar_url(avatar_url)
159-
.public(public_or_private == "public"),
167+
.public(public),
160168
)
161169
.send()
162170
.await
@@ -178,6 +186,49 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
178186
Err(err) => anyhow::bail!("Error contacting API: {}", err.into_message()),
179187
};
180188

189+
match (opts.public, opts.private) {
190+
(true, false) | (false, true) => {
191+
let public = opts.public;
192+
193+
if let Some(public_state) = component.is_public {
194+
if public == public_state {
195+
tracing::info!(
196+
"Component is already {}",
197+
if public { "public" } else { "private" }
198+
);
199+
} else {
200+
tracing::info!(
201+
"Updating component visibility to {}...",
202+
if public { "public" } else { "private" }
203+
);
204+
205+
if !public {
206+
tracing::info!("Only unused components can be made private. If this component is already in use, it will remain public.");
207+
} else {
208+
let confirm = Confirm::new(
209+
"Your component will become publicly visible in the registry. Are you sure?",
210+
)
211+
.with_default(true)
212+
.prompt()?;
213+
214+
if !confirm {
215+
return Ok(());
216+
}
217+
}
218+
client
219+
.update_component_by_slug()
220+
.org_slug(&organization.slug)
221+
.component_slug(&component_slug)
222+
.body(api_types::ComponentUpdateParams::builder().public(public))
223+
.send()
224+
.await
225+
.api_context("Could not update component visibility")?;
226+
}
227+
}
228+
}
229+
_ => {}
230+
}
231+
181232
// Check if version already exists
182233
if component.versions.contains_key(&manifest.component.version) {
183234
anyhow::bail!(

0 commit comments

Comments
 (0)