@@ -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
@@ -178,6 +186,49 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
178
186
Err ( err) => anyhow:: bail!( "Error contacting API: {}" , err. into_message( ) ) ,
179
187
} ;
180
188
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
+
181
232
// Check if version already exists
182
233
if component. versions . contains_key ( & manifest. component . version ) {
183
234
anyhow:: bail!(
0 commit comments