Improve CLI option descriptions

This commit is contained in:
Marcin Kulik
2025-06-02 21:59:10 +02:00
parent 624379680a
commit 1b929911ad
6 changed files with 26 additions and 30 deletions

View File

@@ -29,7 +29,7 @@ pub enum Commands {
/// Stream a terminal session /// Stream a terminal session
Stream(Stream), Stream(Stream),
/// Record and/or stream a terminal session /// Record and stream a terminal session
Session(Session), Session(Session),
/// Concatenate multiple recordings /// Concatenate multiple recordings
@@ -48,7 +48,7 @@ pub enum Commands {
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Record { pub struct Record {
/// Output file path /// Output file path
pub output_path: String, pub file: String,
/// Output file format [default: asciicast-v3] /// Output file format [default: asciicast-v3]
#[arg(short = 'f', long, value_enum, value_name = "FORMAT")] #[arg(short = 'f', long, value_enum, value_name = "FORMAT")]
@@ -58,7 +58,7 @@ pub struct Record {
#[arg(short, long)] #[arg(short, long)]
pub command: Option<String>, pub command: Option<String>,
/// Enable input (keys) recording /// Enable input (keyboard) recording
#[arg(long, short = 'I', alias = "stdin")] #[arg(long, short = 'I', alias = "stdin")]
pub rec_input: bool, pub rec_input: bool,
@@ -106,8 +106,8 @@ pub struct Record {
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Play { pub struct Play {
#[arg(value_name = "FILENAME_OR_URL")] /// A path or an HTTP(S) URL of a recording file
pub filename: String, pub file: String,
/// Limit idle time to a given number of seconds /// Limit idle time to a given number of seconds
#[arg(short, long, value_name = "SECS")] #[arg(short, long, value_name = "SECS")]
@@ -145,7 +145,7 @@ pub struct Stream {
#[arg(short, long)] #[arg(short, long)]
pub command: Option<String>, pub command: Option<String>,
/// Enable input (keys) recording /// Enable input (keyboard) recording
#[arg(long, short = 'I')] #[arg(long, short = 'I')]
pub rec_input: bool, pub rec_input: bool,
@@ -180,7 +180,7 @@ pub struct Stream {
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Session { pub struct Session {
/// Save the session in a file /// Save the session to a file
#[arg(short, long, value_name = "PATH")] #[arg(short, long, value_name = "PATH")]
pub output_file: Option<String>, pub output_file: Option<String>,
@@ -200,7 +200,7 @@ pub struct Session {
#[arg(short, long)] #[arg(short, long)]
pub command: Option<String>, pub command: Option<String>,
/// Enable input (keys) recording /// Enable input (keyboard) recording
#[arg(long, short = 'I')] #[arg(long, short = 'I')]
pub rec_input: bool, pub rec_input: bool,
@@ -248,17 +248,16 @@ pub struct Session {
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Cat { pub struct Cat {
#[arg(required = true, num_args = 2..)] #[arg(required = true, num_args = 2..)]
pub filename: Vec<String>, pub file: Vec<String>,
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Convert { pub struct Convert {
/// File to convert from, in asciicast format (use - for stdin) /// Input asciicast file path, an HTTP(S) URL, or - (for stdin)
#[arg(value_name = "INPUT_FILENAME_OR_URL")] pub input: String,
pub input_filename: String,
/// File to convert to (use - for stdout) /// Output file path, or - (for stdout)
pub output_filename: String, pub output: String,
/// Output file format [default: asciicast-v3] /// Output file format [default: asciicast-v3]
#[arg(short = 'f', long, value_enum, value_name = "FORMAT")] #[arg(short = 'f', long, value_enum, value_name = "FORMAT")]
@@ -271,8 +270,8 @@ pub struct Convert {
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct Upload { pub struct Upload {
/// Filename/path of asciicast to upload /// Path to an asciicast file to upload
pub filename: String, pub file: String,
/// asciinema server URL /// asciinema server URL
#[arg(long, value_name = "URL")] #[arg(long, value_name = "URL")]

View File

@@ -49,10 +49,7 @@ impl cli::Cat {
} }
fn open_input_files(&self) -> Result<Vec<Asciicast>> { fn open_input_files(&self) -> Result<Vec<Asciicast>> {
self.filename self.file.iter().map(asciicast::open_from_path).collect()
.iter()
.map(asciicast::open_from_path)
.collect()
} }
fn get_encoder(&self, version: Version) -> Result<Box<dyn Encoder>> { fn get_encoder(&self, version: Version) -> Result<Box<dyn Encoder>> {

View File

@@ -23,7 +23,7 @@ impl cli::Convert {
fn get_encoder(&self) -> Box<dyn encoder::Encoder> { fn get_encoder(&self) -> Box<dyn encoder::Encoder> {
let format = self.output_format.unwrap_or_else(|| { let format = self.output_format.unwrap_or_else(|| {
if self.output_filename.to_lowercase().ends_with(".txt") { if self.output.to_lowercase().ends_with(".txt") {
Format::Txt Format::Txt
} else { } else {
Format::AsciicastV3 Format::AsciicastV3
@@ -39,18 +39,18 @@ impl cli::Convert {
} }
fn get_input_path(&self) -> Result<Box<dyn AsRef<Path>>> { fn get_input_path(&self) -> Result<Box<dyn AsRef<Path>>> {
if self.input_filename == "-" { if self.input == "-" {
Ok(Box::new(Path::new("/dev/stdin"))) Ok(Box::new(Path::new("/dev/stdin")))
} else { } else {
util::get_local_path(&self.input_filename) util::get_local_path(&self.input)
} }
} }
fn get_output_path(&self) -> String { fn get_output_path(&self) -> String {
if self.output_filename == "-" { if self.output == "-" {
"/dev/stdout".to_owned() "/dev/stdout".to_owned()
} else { } else {
self.output_filename.clone() self.output.clone()
} }
} }

View File

@@ -14,9 +14,9 @@ impl cli::Play {
let speed = self.speed.or(config.playback.speed).unwrap_or(1.0); 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); let idle_time_limit = self.idle_time_limit.or(config.playback.idle_time_limit);
status::info!("Replaying session from {}", self.filename); status::info!("Replaying session from {}", self.file);
let path = util::get_local_path(&self.filename)?; let path = util::get_local_path(&self.file)?;
let keys = get_key_bindings(&config.playback)?; let keys = get_key_bindings(&config.playback)?;
let ended = loop { let ended = loop {

View File

@@ -8,8 +8,8 @@ use crate::config::Config;
impl cli::Upload { impl cli::Upload {
pub fn run(self) -> Result<()> { pub fn run(self) -> Result<()> {
let config = Config::new(self.server_url.clone())?; let config = Config::new(self.server_url.clone())?;
let _ = asciicast::open_from_path(&self.filename)?; let _ = asciicast::open_from_path(&self.file)?;
let response = api::upload_asciicast(&self.filename, &config)?; let response = api::upload_asciicast(&self.file, &config)?;
println!("{}", response.message.unwrap_or(response.url)); println!("{}", response.message.unwrap_or(response.url));
Ok(()) Ok(())

View File

@@ -40,7 +40,7 @@ fn main() -> ExitCode {
match cli.command { match cli.command {
Commands::Rec(cmd) => { Commands::Rec(cmd) => {
let cmd = Session { let cmd = Session {
output_file: Some(cmd.output_path), output_file: Some(cmd.file),
rec_input: cmd.rec_input, rec_input: cmd.rec_input,
append: cmd.append, append: cmd.append,
output_format: cmd.output_format, output_format: cmd.output_format,