8000 feat(share): add --copy option to copy ticket to clipboard by AK-Lmn · Pull Request #7 · osmanahmadxai/beemr · GitHub
[go: up one dir, main page]

Skip to content

feat(share): add --copy option to copy ticket to clipboard - #7

Merged
osmanahmadxai merged 2 commits into
osmanahmadxai:mainfrom
AK-Lmn:feature/copy-ticket-clipboard
Oct 4, 2026
Merged

osmanahmadxai merged 2 commits into
osmanahmadxai:mainfrom
AK-Lmn:feature/copy-ticket-clipboard

Conversation

@AK-Lmn
@AK-Lmn AK-Lmn commented Oct 3, 2026
Copy link
Copy Markdown
Contributor

Closes #3

Summary of Changes

  • Adds --copy flag to beemr share to place the beemr get <ticket> command directly on the clipboard.
  • Implements clipboard execution in src/share.rs:
    • Uses clip.exe on Windows.
    • Uses pbcopy on macOS.
    • Tries wl-copy, falling back to xclip (-selection clipboard), then xsel (--clipboard --input) on Linux.
    • Prints a graceful fallback note on stderr if clipboard command fails or is missing.
  • Adds --copy to the option parsing in src/main.rs.
  • Documents --copy in the README options table and manpage in docs/beemr.1.

@osmanahmadxai osmanahmadxai left a comment
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the structure is good and the docs are in the right places. One blocking bug and a few small things before it can go in:

1. beemr share --copy hangs forever on Linux with xclip, xsel and wl-copy (blocking)

These tools fork a background process that keeps owning the clipboard, and that process inherits our stderr pipe. wait_with_output() reads stderr until end-of-file, which only comes when that background process exits, usually when something else is copied. Since copy_to_clipboard runs before the DHT record is published, the share never starts. I reproduced it in an Alpine container with Xvfb: reading xclip's stderr through a pipe was still blocked after 5 minutes.

The fix is to not capture output, and wait only for the process we started:

let mut child = Command::new(cmd)
    .args(args)
    .stdin(Stdio::piped())
    .stdout(Stdio::null())
    .stderr(Stdio::null())
    .spawn()
    .map_err(|e| e.to_string())?;
if let Some(mut stdin) = child.stdin.take() {
    stdin.write_all(text.as_bytes()).map_err(|e| e.to_string())?;
} // stdin is dropped here, so the tool sees end-of-file
let status = child.wait().map_err(|e| e.to_string())?;
if status.success() { Ok(()) } else { Err(format!("exited with {status}")) }

With that change both xclip and xsel return immediately and the clipboard holds the command.

2. cargo fmt --check fails. Please run cargo fmt; CI checks it.

3. Say when it worked. Please print a confirmation on success, e.g. ✓ Copied the command to the clipboard. For failure, a shorter hint is friendlier than the joined error list, e.g. ✗ Couldn't copy to the clipboard (install wl-clipboard, xclip or xsel) on Linux.

4. Add --copy to the usage text under "Share options:" at the top of src/main.rs, so beemr help lists it.

Happy to merge once these are in.

@AK-Lmn
AK-Lmn force-pushed the feature/copy-ticket-clipboard branch from eeb3baa to 3713000 Compare October 4, 2026 08:58
@AK-Lmn
AK-Lmn commented Oct 4, 2026
Copy link
Copy Markdown
Contributor Author

Hi @osmanahmadxai, thanks for the helpful feedback and reproduction details!

I have addressed all review items:

  1. Avoid blocking on background clipboard tools: Switched to Stdio::null() for stderr/stdout and wait directly on child.wait() so background processes holding the clipboard don't cause wait_with_output() to block on EOF.
  2. Formatting: Formatted code cleanly; cargo fmt --check passes.
  3. User feedback: Prints ? Copied the command to the clipboard on success, and cleaner hints on failure (e.g. ? Couldn't copy to the clipboard (install wl-clipboard, xclip or xsel) on Linux).
  4. Help text: Added --copy under "Share options:" in USAGE (src/main.rs).

@osmanahmadxai
osmanahmadxai merged commit 2a49840 into osmanahmadxai:main Oct 4, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to copy the ticket to the clipboard

2 participants

0