Remove --server-url option from commands that don't use it

This commit is contained in:
Marcin Kulik
2025-05-29 13:16:37 +02:00
parent 8174e207f8
commit 30f3e1abce
8 changed files with 41 additions and 27 deletions

View File

@@ -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<String>,
/// 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<PathBuf>,
/// asciinema server URL
#[arg(long, value_name = "URL")]
pub server_url: Option<String>,
}
#[derive(Debug, Args)]
@@ -223,6 +223,10 @@ pub struct Session {
/// Log file path
#[arg(long, value_name = "PATH")]
pub log_file: Option<PathBuf>,
/// asciinema server URL
#[arg(long, value_name = "URL")]
pub server_url: Option<String>,
}
#[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<String>,
}
#[derive(Debug, Args)]
pub struct Auth {}
pub struct Auth {
/// asciinema server URL
#[arg(long, value_name = "URL")]
pub server_url: Option<String>,
}
#[derive(Clone, Copy, Debug, PartialEq, ValueEnum)]
pub enum Format {

View File

@@ -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");

View File

@@ -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)?;

View File

@@ -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)?;

View File

@@ -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);

View File

@@ -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());

View File

@@ -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(())

View File

@@ -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(),
}
}