Skip to content

Commit f03121a

Browse files
committed
wayland clip board, bump to v1.1, debug.sh
1 parent 07d18ff commit f03121a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "gh-login"
33
authors = ["ldev"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55
license-file="LICENSE.md"
66
edition = "2021"
77
description="A simple git credentials helper for github"
@@ -24,4 +24,4 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
2424
#keyring = {version = "2.0", features=["linux-default-keyutils"]}
2525
shlex = {version= "1.1.0"}
2626
log = {version="0.4"}
27-
stderrlog = {version="0.5"}
27+
stderrlog = {version="0.5"}

debug.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export PATH="$PWD/target/debug:$PATH"

src/main.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use clap::{Parser, Subcommand};
66
use reqwest::Client;
77

88
use log::*;
9+
use std::io::Write;
910
use std::process::{Child, Command, Stdio};
1011
use std::string::String;
1112

@@ -137,15 +138,23 @@ async fn main() {
137138
}
138139
}
139140

140-
fn try_copy_clipboard() -> Result<()> {
141-
let command = Command::new("wl-copy").stdin(Stdio::piped());
141+
fn copy_clipboard(data: String) -> Result<(), String> {
142+
let mut command = Command::new("wl-copy");
143+
command.stdin(Stdio::piped());
142144

143-
let mut stdin = command.stdin.take().unwrap();
144-
stdin.drop(stdin);
145+
let mut process = command.spawn().map_err(|err| err.to_string())?;
146+
let mut stdin = process.stdin.take().unwrap();
147+
stdin.write(data.as_bytes()).unwrap();
145148

146-
let status = command.status()?;
149+
let status = process.wait().map_err(|err| err.to_string())?;
150+
if !status.success() {
151+
return Err(format!(
152+
"wl-copy exited with status code: {}",
153+
status.code().unwrap()
154+
));
155+
}
147156

148-
if !status.success() {}
157+
Ok(())
149158
}
150159

151160
async fn get_access_token_via_device_code(client: &Client) -> ghauth::AccessToken {
@@ -176,7 +185,9 @@ async fn get_device_code(client: &Client) -> ghauth::DeviceCode {
176185
eprintln!("gh-login: Go to the link below and enter in the device code");
177186
eprintln!("{}", device_code.verification_uri);
178187
eprintln!("device code: {}", device_code.user_code);
179-
try_copy_clipboard(device_code.user_code);
188+
if let Some(error) = copy_clipboard(device_code.user_code.to_string()).err() {
189+
warn!("Could not copy to clipboard: {}", error);
190+
}
180191
device_code
181192
}
182193

0 commit comments

Comments
 (0)