From 588c860ee185f7e557d7ccce313ccba1d38ca841 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sat, 3 May 2025 17:28:10 +0200 Subject: [PATCH] Make option names more clear --- src/cli.rs | 118 ++++++++++++++++++++++----------------------- src/cmd/session.rs | 10 ++-- src/config.rs | 26 +++++----- src/main.rs | 16 +++--- 4 files changed, 85 insertions(+), 85 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index feb9249..0dd2efc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,7 +14,7 @@ pub struct Cli { pub command: Commands, /// asciinema server URL - #[arg(long, global = true, display_order = 100)] + #[arg(long, global = true, display_order = 100, value_name = "URL")] pub server_url: Option, /// Quiet mode, i.e. suppress diagnostic messages @@ -52,39 +52,36 @@ pub enum Commands { #[derive(Debug, Args)] pub struct Record { /// Output path - either a file or a directory path - pub path: String, + pub output_path: String, - /// Enable input recording - #[arg(long, short = 'I', alias = "stdin")] - pub input: bool, - - /// Append to an existing recording file - #[arg(short, long)] - pub append: bool, - - /// Recording file format [default: asciicast-v3] - #[arg(short, long, value_enum)] - pub format: Option, - - #[arg(long, hide = true)] - pub raw: bool, - - /// Overwrite target file if it already exists - #[arg(long, conflicts_with = "append")] - pub overwrite: bool, + /// Output file format [default: asciicast-v3] + #[arg(short = 'f', long, value_enum, value_name = "FORMAT")] + pub output_format: Option, /// Command to start in the session [default: $SHELL] #[arg(short, long)] pub command: Option, + /// Enable input (keys) recording + #[arg(long, short = 'I', alias = "stdin")] + pub rec_input: bool, + + /// List of env vars to capture [default: TERM,SHELL] + #[arg(long, value_name = "VARS")] + pub rec_env: Option, + + /// Append to an existing recording file + #[arg(short, long)] + pub append: bool, + + /// Overwrite output file if it already exists + #[arg(long, conflicts_with = "append")] + pub overwrite: bool, + /// Filename template, used when recording to a directory #[arg(long, value_name = "TEMPLATE")] pub filename: Option, - /// List of env vars to save [default: TERM,SHELL] - #[arg(long)] - pub env: Option, - /// Title of the recording #[arg(short, long)] pub title: Option, @@ -93,7 +90,7 @@ pub struct Record { #[arg(short, long, value_name = "SECS")] pub idle_time_limit: Option, - /// Use headless mode - don't use TTY for input/output + /// Headless mode, i.e. don't use TTY for input/output #[arg(long)] pub headless: bool, @@ -106,6 +103,9 @@ pub struct Record { #[arg(long, hide = true)] pub rows: Option, + + #[arg(long, hide = true)] + pub raw: bool, } #[derive(Debug, Args)] @@ -132,14 +132,18 @@ pub struct Play { #[derive(Debug, Args)] pub struct Stream { - /// Enable input capture - #[arg(long, short = 'I', alias = "stdin")] - pub input: bool, - - /// Command to stream [default: $SHELL] + /// Command to start in the session [default: $SHELL] #[arg(short, long)] pub command: Option, + /// Enable input (keys) recording + #[arg(long, short = 'I')] + pub rec_input: bool, + + /// List of env vars to capture [default: TERM,SHELL] + #[arg(long, value_name = "VARS")] + pub rec_env: Option, + /// Serve the stream with the built-in HTTP server #[arg(short, long, value_name = "IP:PORT", default_missing_value = DEFAULT_LISTEN_ADDR, num_args = 0..=1)] pub serve: Option, @@ -148,11 +152,7 @@ pub struct Stream { #[arg(short, long, value_name = "STREAM-ID|WS-URL", default_missing_value = "", num_args = 0..=1, value_parser = validate_forward_target)] pub relay: Option, - /// List of env vars to save [default: TERM,SHELL] - #[arg(long)] - pub env: Option, - - /// Use headless mode - don't use TTY for input/output + /// Headless mode, i.e. don't use TTY for input/output #[arg(long)] pub headless: bool, @@ -161,44 +161,44 @@ pub struct Stream { pub tty_size: Option<(Option, Option)>, /// Log file path - #[arg(long)] + #[arg(long, value_name = "PATH")] pub log_file: Option, } #[derive(Debug, Args)] pub struct Session { /// Output path - either a file or a directory path - #[arg(short, long)] - pub output: Option, + #[arg(short, long, value_name = "PATH")] + pub output_file: Option, - /// Enable input recording - #[arg(long, short = 'I', alias = "stdin")] - pub input: bool, - - /// Append to an existing recording file - #[arg(short, long)] - pub append: bool, - - /// Recording file format [default: asciicast-v3] - #[arg(short, long, value_enum)] - pub format: Option, - - /// Overwrite target file if it already exists - #[arg(long, conflicts_with = "append")] - pub overwrite: bool, + /// Output file format [default: asciicast-v3] + #[arg(short = 'f', long, value_enum, value_name = "FORMAT")] + pub output_format: Option, /// Command to start in the session [default: $SHELL] #[arg(short, long)] pub command: Option, + /// Enable input (keys) recording + #[arg(long, short = 'I')] + pub rec_input: bool, + + /// List of env vars to capture [default: TERM,SHELL] + #[arg(long, value_name = "VARS")] + pub rec_env: Option, + + /// Append to an existing recording file + #[arg(short, long)] + pub append: bool, + + /// Overwrite output file if it already exists + #[arg(long, conflicts_with = "append")] + pub overwrite: bool, + /// Filename template, used when recording to a directory #[arg(long, value_name = "TEMPLATE")] pub filename: Option, - /// List of env vars to save [default: TERM,SHELL] - #[arg(long)] - pub env: Option, - /// Title of the recording #[arg(short, long)] pub title: Option, @@ -207,7 +207,7 @@ pub struct Session { #[arg(short, long, value_name = "SECS")] pub idle_time_limit: Option, - /// Use headless mode - don't use TTY for input/output + /// Headless mode, i.e. don't use TTY for input/output #[arg(long)] pub headless: bool, @@ -224,7 +224,7 @@ pub struct Session { pub relay: Option, /// Log file path - #[arg(long)] + #[arg(long, value_name = "PATH")] pub log_file: Option, } diff --git a/src/cmd/session.rs b/src/cmd/session.rs index a020bc6..4dfa67c 100644 --- a/src/cmd/session.rs +++ b/src/cmd/session.rs @@ -42,13 +42,13 @@ impl cli::Session { let command = self.get_command(cmd_config); let keys = get_key_bindings(cmd_config)?; let notifier = notifier::threaded(get_notifier(config)); - let record_input = self.input || cmd_config.input; + let record_input = self.rec_input || cmd_config.rec_input; let term_type = self.get_term_type(); let term_version = self.get_term_version()?; - let env = capture_env(self.env.clone(), cmd_config); + let env = capture_env(self.rec_env.clone(), cmd_config); let path = self - .output + .output_file .take() .map(|path| self.ensure_filename(path, cmd_config)) .transpose()?; @@ -232,7 +232,7 @@ impl cli::Session { env: &HashMap, notifier: N, ) -> Result { - let format = self.format.unwrap_or_else(|| { + let format = self.output_format.unwrap_or_else(|| { if path.to_lowercase().ends_with(".txt") { Format::Txt } else { @@ -496,7 +496,7 @@ fn get_key_bindings(config: &config::Session) -> Result { fn capture_env(var_names: Option, config: &config::Session) -> HashMap { let var_names = var_names - .or(config.env.clone()) + .or(config.rec_env.clone()) .unwrap_or(String::from("TERM,SHELL")); let vars = var_names.split(',').collect::>(); diff --git a/src/config.rs b/src/config.rs index 1784f90..fc959f7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -42,8 +42,8 @@ pub struct Cmd { pub struct Session { pub command: Option, pub filename: String, - pub input: bool, - pub env: Option, + pub rec_input: bool, + pub rec_env: Option, pub idle_time_limit: Option, pub prefix_key: Option, pub pause_key: Option, @@ -55,8 +55,8 @@ pub struct Session { pub struct Rec { pub command: Option, pub filename: String, - pub input: bool, - pub env: Option, + pub rec_input: bool, + pub rec_env: Option, pub idle_time_limit: Option, pub prefix_key: Option, pub pause_key: Option, @@ -77,8 +77,8 @@ pub struct Play { #[allow(unused)] pub struct Stream { pub command: Option, - pub input: bool, - pub env: Option, + pub rec_input: bool, + pub rec_env: Option, pub prefix_key: Option, pub pause_key: Option, pub add_marker_key: Option, @@ -95,11 +95,11 @@ impl Config { pub fn new(server_url: Option) -> Result { let mut config = config::Config::builder() .set_default("server.url", None::>)? - .set_default("cmd.rec.input", false)? + .set_default("cmd.rec.rec_input", false)? .set_default("cmd.rec.filename", DEFAULT_REC_FILENAME)? .set_default("cmd.play.speed", None::>)? - .set_default("cmd.stream.input", false)? - .set_default("cmd.session.input", false)? + .set_default("cmd.stream.rec_input", false)? + .set_default("cmd.session.rec_input", false)? .set_default("cmd.session.filename", DEFAULT_REC_FILENAME)? .set_default("notifications.enabled", true)? .add_source(config::File::with_name("/etc/asciinema/config.toml").required(false)) @@ -155,8 +155,8 @@ impl Config { Session { command: self.cmd.rec.command.clone(), filename: self.cmd.rec.filename.clone(), - input: self.cmd.rec.input, - env: self.cmd.rec.env.clone(), + rec_input: self.cmd.rec.rec_input, + rec_env: self.cmd.rec.rec_env.clone(), idle_time_limit: self.cmd.rec.idle_time_limit, prefix_key: self.cmd.rec.prefix_key.clone(), pause_key: self.cmd.rec.pause_key.clone(), @@ -168,8 +168,8 @@ impl Config { Session { command: self.cmd.stream.command.clone(), filename: "".to_string(), - input: self.cmd.stream.input, - env: self.cmd.stream.env.clone(), + rec_input: self.cmd.stream.rec_input, + rec_env: self.cmd.stream.rec_env.clone(), idle_time_limit: None, prefix_key: self.cmd.stream.prefix_key.clone(), pause_key: self.cmd.stream.pause_key.clone(), diff --git a/src/main.rs b/src/main.rs index 3ff027a..a66af9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,14 +38,14 @@ fn main() -> anyhow::Result<()> { match cli.command { Commands::Rec(cmd) => { let cmd = Session { - output: Some(cmd.path), - input: cmd.input, + output_file: Some(cmd.output_path), + rec_input: cmd.rec_input, append: cmd.append, - format: cmd.format, + output_format: cmd.output_format, overwrite: cmd.overwrite, command: cmd.command, filename: cmd.filename, - env: cmd.env, + rec_env: cmd.rec_env, title: cmd.title, idle_time_limit: cmd.idle_time_limit, headless: cmd.headless, @@ -60,14 +60,14 @@ fn main() -> anyhow::Result<()> { Commands::Stream(stream) => { let cmd = Session { - output: None, - input: stream.input, + output_file: None, + rec_input: stream.rec_input, append: false, - format: None, + output_format: None, overwrite: false, command: stream.command, filename: None, - env: stream.env, + rec_env: stream.rec_env, title: None, idle_time_limit: None, headless: stream.headless,