Skip to content

Commit 81aa2c1

Browse files
committed
feat(cli): add 'bridge register' command and cleanup unused imports
1 parent 1377db5 commit 81aa2c1

5 files changed

Lines changed: 42 additions & 9 deletions

File tree

crates/bridge/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ pub mod protocol;
22
pub mod peer_identity;
33

44
pub use interprocess::local_socket::tokio::{LocalSocketListener, LocalSocketStream};
5-
#[cfg(unix)]
6-
use std::os::unix::io::AsRawFd;
7-
#[cfg(windows)]
8-
use std::os::windows::io::AsRawHandle;
9-
10-
use crate::peer_identity::{PeerIdentity, get_peer_identity};
115

126
// Re-export protocol
137
pub use protocol::{BridgeService, BridgeServiceClient, BridgeError};
148

159
use tarpc::server::{BaseChannel, Channel};
16-
use tokio::io::{AsyncRead, AsyncWrite};
1710
use futures::StreamExt;
1811

1912
pub struct BridgeServer;

crates/bridge/src/peer_identity.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::io;
2-
31
#[derive(Debug, Clone, Copy)]
42
pub struct PeerIdentity {
53
pub uid: Option<u32>,

crates/cli/src/cli/bridge.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use anyhow::Result;
2+
use clap::{Args, Subcommand};
3+
use localgpt_core::security::BridgeManager;
4+
5+
#[derive(Args)]
6+
pub struct BridgeArgs {
7+
#[command(subcommand)]
8+
pub command: BridgeCommands,
9+
}
10+
11+
#[derive(Subcommand)]
12+
pub enum BridgeCommands {
13+
/// Register a new bridge with credentials
14+
Register {
15+
/// Unique ID for the bridge (e.g., "telegram")
16+
#[arg(long)]
17+
id: String,
18+
19+
/// Secret key/token for the bridge
20+
#[arg(long)]
21+
secret: String,
22+
},
23+
}
24+
25+
pub async fn run(args: BridgeArgs) -> Result<()> {
26+
match args.command {
27+
BridgeCommands::Register { id, secret } => {
28+
let manager = BridgeManager::new();
29+
manager.register_bridge(&id, secret.as_bytes()).await?;
30+
// Note: Logging is handled by the core logging system, initialized in main.
31+
// But we can print to stdout for CLI feedback.
32+
println!("Bridge '{}' registered successfully.", id);
33+
println!("You may need to restart the daemon for changes to take effect.");
34+
}
35+
}
36+
Ok(())
37+
}

crates/cli/src/cli/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod ask;
22
pub mod auth;
3+
pub mod bridge;
34
pub mod chat;
45
pub mod config;
56
pub mod daemon;
@@ -81,4 +82,7 @@ pub enum Commands {
8182

8283
/// Authenticate with providers (Gemini, etc.)
8384
Auth(auth::AuthArgs),
85+
86+
/// Manage bridges and credentials
87+
Bridge(bridge::BridgeArgs),
8488
}

crates/cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@ async fn async_main(cli: Cli) -> Result<()> {
8585
Commands::Sandbox(args) => crate::cli::sandbox::run(args).await,
8686
Commands::Search(args) => crate::cli::search::run(args).await,
8787
Commands::Auth(args) => crate::cli::auth::run(args).await,
88+
Commands::Bridge(args) => crate::cli::bridge::run(args).await,
8889
}
8990
}

0 commit comments

Comments
 (0)