mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-15 19:28:00 +01:00
Fix double prompt for server URL
This commit is contained in:
13
src/api.rs
13
src/api.rs
@@ -45,14 +45,14 @@ struct ErrorResponse {
|
||||
message: String,
|
||||
}
|
||||
|
||||
pub fn get_auth_url(config: &Config) -> Result<Url> {
|
||||
pub fn get_auth_url(config: &mut Config) -> Result<Url> {
|
||||
let mut url = config.get_server_url()?;
|
||||
url.set_path(&format!("connect/{}", config.get_install_id()?));
|
||||
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
pub async fn create_recording(path: &str, config: &Config) -> Result<RecordingResponse> {
|
||||
pub async fn create_recording(path: &str, config: &mut Config) -> Result<RecordingResponse> {
|
||||
let server_url = &config.get_server_url()?;
|
||||
let install_id = config.get_install_id()?;
|
||||
|
||||
@@ -92,7 +92,7 @@ async fn create_recording_request(
|
||||
Ok(add_headers(builder, &install_id))
|
||||
}
|
||||
|
||||
pub async fn list_user_streams(prefix: &str, config: &Config) -> Result<Vec<StreamResponse>> {
|
||||
pub async fn list_user_streams(prefix: &str, config: &mut Config) -> Result<Vec<StreamResponse>> {
|
||||
let server_url = config.get_server_url()?;
|
||||
let install_id = config.get_install_id()?;
|
||||
|
||||
@@ -113,7 +113,10 @@ fn list_user_streams_request(server_url: &Url, prefix: &str, install_id: &str) -
|
||||
add_headers(client.get(url), install_id)
|
||||
}
|
||||
|
||||
pub async fn create_stream(changeset: StreamChangeset, config: &Config) -> Result<StreamResponse> {
|
||||
pub async fn create_stream(
|
||||
changeset: StreamChangeset,
|
||||
config: &mut Config,
|
||||
) -> Result<StreamResponse> {
|
||||
let server_url = config.get_server_url()?;
|
||||
let install_id = config.get_install_id()?;
|
||||
|
||||
@@ -142,7 +145,7 @@ fn create_stream_request(
|
||||
pub async fn update_stream(
|
||||
stream_id: u64,
|
||||
changeset: StreamChangeset,
|
||||
config: &Config,
|
||||
config: &mut Config,
|
||||
) -> Result<StreamResponse> {
|
||||
let server_url = config.get_server_url()?;
|
||||
let install_id = config.get_install_id()?;
|
||||
|
||||
@@ -6,10 +6,10 @@ use crate::config::Config;
|
||||
|
||||
impl cli::Auth {
|
||||
pub fn run(self) -> Result<()> {
|
||||
let config = Config::new(self.server_url.clone())?;
|
||||
let mut config = Config::new(self.server_url.clone())?;
|
||||
let server_url = config.get_server_url()?;
|
||||
let server_hostname = server_url.host().unwrap();
|
||||
let auth_url = api::get_auth_url(&config)?;
|
||||
let auth_url = api::get_auth_url(&mut config)?;
|
||||
|
||||
println!("Open the following URL in a web browser to authenticate this CLI with your {server_hostname} user account:\n");
|
||||
println!("{auth_url}\n");
|
||||
|
||||
@@ -47,14 +47,14 @@ impl cli::Session {
|
||||
}
|
||||
|
||||
async fn do_run(&mut self) -> Result<i32> {
|
||||
let config = Config::new(self.server_url.clone())?;
|
||||
let mut config = Config::new(self.server_url.clone())?;
|
||||
let command = self.get_command(&config.session);
|
||||
let keys = get_key_bindings(&config.session)?;
|
||||
let notifier = get_notifier(&config);
|
||||
let metadata = self.get_session_metadata(&config.session).await?;
|
||||
let file_writer = self.get_file_writer(&metadata, notifier.clone()).await?;
|
||||
let listener = self.get_listener().await?;
|
||||
let relay = self.get_relay(&metadata, &config).await?;
|
||||
let relay = self.get_relay(&metadata, &mut config).await?;
|
||||
let relay_id = relay.as_ref().map(|r| r.id());
|
||||
let parent_session_relay_id = get_parent_session_relay_id();
|
||||
|
||||
@@ -312,7 +312,7 @@ impl cli::Session {
|
||||
async fn get_relay(
|
||||
&mut self,
|
||||
metadata: &Metadata,
|
||||
config: &config::Config,
|
||||
config: &mut config::Config,
|
||||
) -> Result<Option<Relay>> {
|
||||
let Some(target) = &self.stream_remote else {
|
||||
return Ok(None);
|
||||
@@ -341,7 +341,7 @@ impl cli::Session {
|
||||
&self,
|
||||
id: &str,
|
||||
metadata: &Metadata,
|
||||
config: &Config,
|
||||
config: &mut Config,
|
||||
) -> Result<StreamResponse> {
|
||||
let env = if metadata.env.is_empty() {
|
||||
Some(None)
|
||||
|
||||
@@ -12,9 +12,9 @@ impl cli::Upload {
|
||||
}
|
||||
|
||||
async fn do_run(self) -> Result<()> {
|
||||
let config = Config::new(self.server_url.clone())?;
|
||||
let mut config = Config::new(self.server_url.clone())?;
|
||||
let _ = asciicast::open_from_path(&self.file)?;
|
||||
let response = api::create_recording(&self.file, &config).await?;
|
||||
let response = api::create_recording(&self.file, &mut config).await?;
|
||||
println!("{}", response.message.unwrap_or(response.url));
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -87,13 +87,14 @@ impl Config {
|
||||
Ok(config.build()?.try_deserialize()?)
|
||||
}
|
||||
|
||||
pub fn get_server_url(&self) -> Result<Url> {
|
||||
pub fn get_server_url(&mut self) -> Result<Url> {
|
||||
match self.server.url.as_ref() {
|
||||
Some(url) => Ok(parse_server_url(url)?),
|
||||
|
||||
None => {
|
||||
let url = parse_server_url(&ask_for_server_url()?)?;
|
||||
save_default_server_url(url.as_ref())?;
|
||||
self.server.url = Some(url.to_string());
|
||||
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user