Skip to content

Commit

Permalink
Support claiming selection ownership with cli add command (closes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Saveau committed Nov 9, 2024
1 parent e491643 commit ddd54b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/command-reference-short.golden
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Arguments:
Options:
-f, --favorite Whether to add the entry to the favorites ring
-m, --mime-type <MIME_TYPE> The entry mime type
-c, --copy Whether to overwrite the system clipboard with this entry
-h, --help Print help (use `--help` for more detail)

---
Expand Down
3 changes: 3 additions & 0 deletions cli/command-reference.golden
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Options:
-m, --mime-type <MIME_TYPE>
The entry mime type

-c, --copy
Whether to overwrite the system clipboard with this entry

-h, --help
Print help (use `-h` for a summary)

Expand Down
24 changes: 22 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ use ringboard_sdk::{
ClientError, DatabaseReader, EntryReader, Kind,
api::{
AddRequest, GarbageCollectRequest, MoveToFrontRequest, RemoveRequest, SwapRequest,
connect_to_server, connect_to_server_with,
connect_to_paste_server, connect_to_server, connect_to_server_with, send_paste_buffer,
},
config::{X11Config, X11V1Config, x11_config_file},
core::{
BucketAndIndex, Error as CoreError, IoErr, NUM_BUCKETS, SendQuitAndWait, acquire_lock_file,
bucket_to_length, copy_file_range_all, create_tmp_file,
dirs::{data_dir, socket_file},
dirs::{data_dir, paste_socket_file, socket_file},
protocol::{
AddResponse, GarbageCollectResponse, IdNotFoundError, MimeType, MoveToFrontResponse,
RemoveResponse, Response, RingKind, SwapResponse, decompose_id,
Expand Down Expand Up @@ -228,6 +228,11 @@ struct Add {
/// The entry mime type.
#[clap(short, long, short_alias = 't', alias = "target")]
mime_type: Option<MimeType>,

/// Whether to overwrite the system clipboard with this entry.
#[clap(short, long)]
#[clap(default_value_t = false)]
copy: bool,
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -628,6 +633,7 @@ fn add(
data_file,
favorite,
mime_type,
copy,
}: Add,
) -> Result<(), CliError> {
let AddResponse::Success { id } = {
Expand Down Expand Up @@ -660,6 +666,20 @@ fn add(

println!("Entry added: {id}");

if copy {
let (mut database, mut reader) = open_db()?;
let entry = unsafe { database.get(id)? };

let paste_server = {
let socket_file = paste_socket_file();
let addr = SocketAddrUnix::new(&socket_file)
.map_io_err(|| format!("Failed to make socket address: {socket_file:?}"))?;
connect_to_paste_server(&addr)?
};

send_paste_buffer(paste_server, entry, &mut reader, false)?;
}

Ok(())
}

Expand Down

0 comments on commit ddd54b6

Please sign in to comment.