⭐️ A friendly language for building type-safe, scalable systems!
0

Configure Feed

Select the types of activity you want to include in your feed.

gleam / compiler-cli / src / owner.rs
2.0 kB 62 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2025 The Gleam contributors 3 4use crate::{cli, http::HttpClient}; 5use gleam_core::{Result, hex}; 6 7pub fn add( 8 package: String, 9 new_owner_username_or_email: String, 10 level: hexpm::OwnerLevel, 11) -> Result<()> { 12 let runtime = tokio::runtime::Runtime::new().expect("Unable to start Tokio async runtime"); 13 let http = HttpClient::new(); 14 let hex_config = hexpm::Config::new(); 15 let credentials = crate::hex::HexAuthentication::new(&runtime, &http, hex_config.clone()) 16 .get_or_create_api_credentials()?; 17 18 cli::print_adding_owner(); 19 runtime.block_on(hex::add_owner( 20 &crate::hex::write_credentials(&credentials)?, 21 package, 22 new_owner_username_or_email, 23 level, 24 &hex_config, 25 &http, 26 ))?; 27 cli::print_added_owner(); 28 29 Ok(()) 30} 31 32pub fn transfer(package: String, new_owner_username_or_email: String) -> Result<()> { 33 println!( 34 "Transferring ownership of this package will remove all current owners and make 35{new_owner_username_or_email} its new owner. 36Do you wish to transfer ownership of `{package}` to {new_owner_username_or_email}?", 37 ); 38 39 let should_transfer_ownership = cli::confirm_with_text(&package)?; 40 if !should_transfer_ownership { 41 println!("Not transferring ownership."); 42 return Ok(()); 43 } 44 45 let runtime = tokio::runtime::Runtime::new().expect("Unable to start Tokio async runtime"); 46 let http = HttpClient::new(); 47 let hex_config = hexpm::Config::new(); 48 let credentials = crate::hex::HexAuthentication::new(&runtime, &http, hex_config.clone()) 49 .get_or_create_api_credentials()?; 50 51 cli::print_transferring_ownership(); 52 runtime.block_on(hex::transfer_owner( 53 &crate::hex::write_credentials(&credentials)?, 54 package, 55 new_owner_username_or_email, 56 &hex_config, 57 &HttpClient::new(), 58 ))?; 59 cli::print_transferred_ownership(); 60 61 Ok(()) 62}