Skip to content

Commit dc08c23

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

File tree

1 file changed

+49
-7
lines changed
  • crates/cli/src/commands/components

1 file changed

+49
-7
lines changed

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

+49-7
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
@@ -252,6 +260,40 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
252260
}
253261
}
254262

263+
let public = match (opts.public, opts.private) {
264+
(true, false) | (false, true) => {
265+
let public = opts.public;
266+
let remote_public = component.is_public.unwrap_or(false);
267+
if opts.public == remote_public {
268+
tracing::info!(
269+
"Component is already {}",
270+
if public { "public" } else { "private" }
271+
);
272+
} else {
273+
tracing::info!(
274+
"Updating component visibility to {}...",
275+
if public { "public" } else { "private" }
276+
);
277+
278+
if !public {
279+
tracing::info!("Only unused components can be made private. If this component is already in use, it will remain public.");
280+
} else {
281+
let confirm = Confirm::new(
282+
"Your component will become publicly visible in the registry. Are you sure?",
283+
)
284+
.with_default(true)
285+
.prompt()?;
286+
287+
if !confirm {
288+
return Ok(());
289+
}
290+
}
291+
}
292+
public
293+
}
294+
_ => component.is_public.unwrap_or(false),
295+
};
296+
255297
client
256298
.update_component_by_slug()
257299
.org_slug(&organization.slug)
@@ -260,7 +302,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
260302
api_types::ComponentUpdateParams::builder()
261303
.name(manifest.component.name.clone())
262304
.description(manifest.component.description.clone())
263-
.public(component.is_public)
305+
.public(public)
264306
.documentation_link(
265307
manifest
266308
.component

0 commit comments

Comments
 (0)