Make option names more clear

This commit is contained in:
Marcin Kulik
2025-05-03 17:28:10 +02:00
parent f0f74e92f5
commit 588c860ee1
4 changed files with 85 additions and 85 deletions

View File

@@ -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<String>,
/// 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<Format>,
#[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<Format>,
/// Command to start in the session [default: $SHELL]
#[arg(short, long)]
pub command: Option<String>,
/// 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<String>,
/// 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<String>,
/// List of env vars to save [default: TERM,SHELL]
#[arg(long)]
pub env: Option<String>,
/// Title of the recording
#[arg(short, long)]
pub title: Option<String>,
@@ -93,7 +90,7 @@ pub struct Record {
#[arg(short, long, value_name = "SECS")]
pub idle_time_limit: Option<f64>,
/// 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<u16>,
#[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<String>,
/// 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<String>,
/// 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<SocketAddr>,
@@ -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<RelayTarget>,
/// List of env vars to save [default: TERM,SHELL]
#[arg(long)]
pub env: Option<String>,
/// 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<u16>, Option<u16>)>,
/// Log file path
#[arg(long)]
#[arg(long, value_name = "PATH")]
pub log_file: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct Session {
/// Output path - either a file or a directory path
#[arg(short, long)]
pub output: Option<String>,
#[arg(short, long, value_name = "PATH")]
pub output_file: Option<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<Format>,
/// 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<Format>,
/// Command to start in the session [default: $SHELL]
#[arg(short, long)]
pub command: Option<String>,
/// 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<String>,
/// 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<String>,
/// List of env vars to save [default: TERM,SHELL]
#[arg(long)]
pub env: Option<String>,
/// Title of the recording
#[arg(short, long)]
pub title: Option<String>,
@@ -207,7 +207,7 @@ pub struct Session {
#[arg(short, long, value_name = "SECS")]
pub idle_time_limit: Option<f64>,
/// 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<RelayTarget>,
/// Log file path
#[arg(long)]
#[arg(long, value_name = "PATH")]
pub log_file: Option<PathBuf>,
}

View File

@@ -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<String, String>,
notifier: N,
) -> Result<FileWriterStarter> {
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<KeyBindings> {
fn capture_env(var_names: Option<String>, config: &config::Session) -> HashMap<String, String> {
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::<HashSet<_>>();

View File

@@ -42,8 +42,8 @@ pub struct Cmd {
pub struct Session {
pub command: Option<String>,
pub filename: String,
pub input: bool,
pub env: Option<String>,
pub rec_input: bool,
pub rec_env: Option<String>,
pub idle_time_limit: Option<f64>,
pub prefix_key: Option<String>,
pub pause_key: Option<String>,
@@ -55,8 +55,8 @@ pub struct Session {
pub struct Rec {
pub command: Option<String>,
pub filename: String,
pub input: bool,
pub env: Option<String>,
pub rec_input: bool,
pub rec_env: Option<String>,
pub idle_time_limit: Option<f64>,
pub prefix_key: Option<String>,
pub pause_key: Option<String>,
@@ -77,8 +77,8 @@ pub struct Play {
#[allow(unused)]
pub struct Stream {
pub command: Option<String>,
pub input: bool,
pub env: Option<String>,
pub rec_input: bool,
pub rec_env: Option<String>,
pub prefix_key: Option<String>,
pub pause_key: Option<String>,
pub add_marker_key: Option<String>,
@@ -95,11 +95,11 @@ impl Config {
pub fn new(server_url: Option<String>) -> Result<Self> {
let mut config = config::Config::builder()
.set_default("server.url", None::<Option<String>>)?
.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::<Option<f64>>)?
.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(),

View File

@@ -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,