@@ -12,6 +12,7 @@ pub struct Options {
12
12
///
13
13
/// Defaults to the user "self" org
14
14
pub organization : Option < String > ,
15
+
15
16
#[ arg( long, conflicts_with = "private" ) ]
16
17
pub public : bool ,
17
18
@@ -118,11 +119,18 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
118
119
return Ok ( ( ) ) ;
119
120
}
120
121
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
+ } ;
126
134
127
135
let avatar_url = if let Some ( path) = & manifest. component . icon_path {
128
136
tracing:: info!( "Uploading Icon... {:?}" , manifest. component. icon_path) ;
@@ -156,7 +164,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
156
164
. map ( |url| url. to_string ( ) ) ,
157
165
)
158
166
. avatar_url ( avatar_url)
159
- . public ( public_or_private == " public" ) ,
167
+ . public ( public) ,
160
168
)
161
169
. send ( )
162
170
. await
@@ -252,6 +260,40 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
252
260
}
253
261
}
254
262
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
+
255
297
client
256
298
. update_component_by_slug ( )
257
299
. org_slug ( & organization. slug )
@@ -260,7 +302,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
260
302
api_types:: ComponentUpdateParams :: builder ( )
261
303
. name ( manifest. component . name . clone ( ) )
262
304
. description ( manifest. component . description . clone ( ) )
263
- . public ( component . is_public )
305
+ . public ( public )
264
306
. documentation_link (
265
307
manifest
266
308
. component
0 commit comments