From 30f3e1abce634a31835accdd654627c724b18cc5 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 29 May 2025 13:16:37 +0200 Subject: [PATCH] Remove `--server-url` option from commands that don't use it --- src/cli.rs | 22 +++++++++++++++++----- src/cmd/auth.rs | 5 +++-- src/cmd/cat.rs | 3 +-- src/cmd/convert.rs | 3 +-- src/cmd/play.rs | 3 ++- src/cmd/session.rs | 7 ++++--- src/cmd/upload.rs | 5 +++-- src/main.rs | 20 ++++++++++---------- 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 8245b5e..bed072e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,10 +13,6 @@ pub struct Cli { #[command(subcommand)] pub command: Commands, - /// asciinema server URL - #[arg(long, global = true, display_order = 100, value_name = "URL")] - pub server_url: Option, - /// Quiet mode, i.e. suppress diagnostic messages #[clap(short, long, global = true, display_order = 101)] pub quiet: bool, @@ -164,6 +160,10 @@ pub struct Stream { /// Log file path #[arg(long, value_name = "PATH")] pub log_file: Option, + + /// asciinema server URL + #[arg(long, value_name = "URL")] + pub server_url: Option, } #[derive(Debug, Args)] @@ -223,6 +223,10 @@ pub struct Session { /// Log file path #[arg(long, value_name = "PATH")] pub log_file: Option, + + /// asciinema server URL + #[arg(long, value_name = "URL")] + pub server_url: Option, } #[derive(Debug, Args)] @@ -253,10 +257,18 @@ pub struct Convert { pub struct Upload { /// Filename/path of asciicast to upload pub filename: String, + + /// asciinema server URL + #[arg(long, value_name = "URL")] + pub server_url: Option, } #[derive(Debug, Args)] -pub struct Auth {} +pub struct Auth { + /// asciinema server URL + #[arg(long, value_name = "URL")] + pub server_url: Option, +} #[derive(Clone, Copy, Debug, PartialEq, ValueEnum)] pub enum Format { diff --git a/src/cmd/auth.rs b/src/cmd/auth.rs index ca5a700..b60db2a 100644 --- a/src/cmd/auth.rs +++ b/src/cmd/auth.rs @@ -5,10 +5,11 @@ use crate::cli; use crate::config::Config; impl cli::Auth { - pub fn run(self, config: &Config) -> Result<()> { + pub fn run(self) -> Result<()> { + let 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(&config)?; println!("Open the following URL in a web browser to authenticate this asciinema CLI with your {server_hostname} user account:\n"); println!("{auth_url}\n"); diff --git a/src/cmd/cat.rs b/src/cmd/cat.rs index d8f1cd9..c98be52 100644 --- a/src/cmd/cat.rs +++ b/src/cmd/cat.rs @@ -5,10 +5,9 @@ use anyhow::{anyhow, Result}; use crate::asciicast::{self, Asciicast, Encoder, Version}; use crate::cli; -use crate::config::Config; impl cli::Cat { - pub fn run(self, _config: &Config) -> Result<()> { + pub fn run(self) -> Result<()> { let mut stdout = io::stdout(); let casts = self.open_input_files()?; let mut encoder = self.get_encoder(casts[0].version)?; diff --git a/src/cmd/convert.rs b/src/cmd/convert.rs index cc1266f..2fe7c63 100644 --- a/src/cmd/convert.rs +++ b/src/cmd/convert.rs @@ -5,14 +5,13 @@ use anyhow::{bail, Result}; use crate::asciicast; use crate::cli::{self, Format}; -use crate::config::Config; use crate::encoder::{ self, AsciicastV2Encoder, AsciicastV3Encoder, EncoderExt, RawEncoder, TextEncoder, }; use crate::util; impl cli::Convert { - pub fn run(self, _config: &Config) -> Result<()> { + pub fn run(self) -> Result<()> { let input_path = self.get_input_path()?; let output_path = self.get_output_path(); let cast = asciicast::open_from_path(&*input_path)?; diff --git a/src/cmd/play.rs b/src/cmd/play.rs index 51c5836..f72216f 100644 --- a/src/cmd/play.rs +++ b/src/cmd/play.rs @@ -9,7 +9,8 @@ use crate::tty; use crate::util; impl cli::Play { - pub fn run(self, config: &Config) -> Result<()> { + pub fn run(self) -> Result<()> { + let config = Config::new(None)?; let speed = self.speed.or(config.playback.speed).unwrap_or(1.0); let idle_time_limit = self.idle_time_limit.or(config.playback.idle_time_limit); diff --git a/src/cmd/session.rs b/src/cmd/session.rs index 88391fd..28fca56 100644 --- a/src/cmd/session.rs +++ b/src/cmd/session.rs @@ -33,13 +33,14 @@ use crate::stream::Stream; use crate::tty::{DevTty, FixedSizeTty, NullTty, Tty}; impl cli::Session { - pub fn run(mut self, config: &Config) -> Result<()> { + pub fn run(mut self) -> Result<()> { locale::check_utf8_locale()?; + let config = Config::new(self.server_url.clone())?; let runtime = Runtime::new()?; let command = self.get_command(&config.recording); let keys = get_key_bindings(&config.recording)?; - let notifier = notifier::threaded(get_notifier(config)); + let notifier = notifier::threaded(get_notifier(&config)); let record_input = self.rec_input || config.recording.rec_input; let term_type = self.get_term_type(); let term_version = self.get_term_version()?; @@ -70,7 +71,7 @@ impl cli::Session { let mut relay = self .stream_remote .take() - .map(|target| get_relay(target, config, term_type, term_version, &env)) + .map(|target| get_relay(target, &config, term_type, term_version, &env)) .transpose()?; let relay_id = relay.as_ref().map(|r| r.id()); diff --git a/src/cmd/upload.rs b/src/cmd/upload.rs index bf81a33..80c7890 100644 --- a/src/cmd/upload.rs +++ b/src/cmd/upload.rs @@ -6,9 +6,10 @@ use crate::cli; use crate::config::Config; impl cli::Upload { - pub fn run(self, config: &Config) -> Result<()> { + pub fn run(self) -> Result<()> { + let config = Config::new(self.server_url.clone())?; let _ = asciicast::open_from_path(&self.filename)?; - let response = api::upload_asciicast(&self.filename, config)?; + let response = api::upload_asciicast(&self.filename, &config)?; println!("{}", response.message.unwrap_or(response.url)); Ok(()) diff --git a/src/main.rs b/src/main.rs index 4d497ac..0d4e054 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,11 +25,9 @@ mod util; use clap::Parser; use self::cli::{Cli, Commands, Session}; -use self::config::Config; fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - let config = Config::new(cli.server_url.clone())?; if cli.quiet { status::disable(); @@ -54,9 +52,10 @@ fn main() -> anyhow::Result<()> { stream_local: None, stream_remote: None, log_file: None, + server_url: None, }; - cmd.run(&config) + cmd.run() } Commands::Stream(stream) => { @@ -75,16 +74,17 @@ fn main() -> anyhow::Result<()> { stream_local: stream.local, stream_remote: stream.remote, log_file: stream.log_file, + server_url: stream.server_url, }; - cmd.run(&config) + cmd.run() } - Commands::Session(cmd) => cmd.run(&config), - Commands::Play(cmd) => cmd.run(&config), - Commands::Cat(cmd) => cmd.run(&config), - Commands::Convert(cmd) => cmd.run(&config), - Commands::Upload(cmd) => cmd.run(&config), - Commands::Auth(cmd) => cmd.run(&config), + Commands::Session(cmd) => cmd.run(), + Commands::Play(cmd) => cmd.run(), + Commands::Cat(cmd) => cmd.run(), + Commands::Convert(cmd) => cmd.run(), + Commands::Upload(cmd) => cmd.run(), + Commands::Auth(cmd) => cmd.run(), } }