Skip to content

Commit 5a28250

Browse files
authored
Add get_runtime() helper for runtime initialization (#134)
2 parents ac27031 + c051a21 commit 5a28250

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

cli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ version = "0.4.0-pre.4"
44
edition = "2021"
55
repository = "https://github.com/tursodatabase/agentfs"
66

7+
[lib]
8+
name = "agentfs"
9+
path = "src/lib.rs"
10+
711
[[bin]]
812
name = "agentfs"
913
path = "src/main.rs"

cli/src/cmd/mount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn mount(args: MountArgs) -> Result<()> {
6262
};
6363

6464
let mount = move || {
65-
let rt = tokio::runtime::Runtime::new()?;
65+
let rt = crate::get_runtime();
6666
let agentfs = rt.block_on(AgentFS::open(opts))?;
6767

6868
// Check for overlay configuration

cli/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub mod cmd;
2+
pub mod parser;
3+
pub mod sandbox;
4+
5+
#[cfg(any(target_os = "linux", target_os = "macos"))]
6+
pub mod daemon;
7+
8+
#[cfg(any(target_os = "linux", target_os = "macos"))]
9+
pub mod fuse;
10+
11+
#[cfg(target_os = "macos")]
12+
pub mod nfs;
13+
14+
pub fn get_runtime() -> tokio::runtime::Runtime {
15+
tokio::runtime::Runtime::new().expect("Internal error: failed to initialize runtime")
16+
}

cli/src/main.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
mod cmd;
2-
mod parser;
3-
mod sandbox;
4-
5-
#[cfg(any(target_os = "linux", target_os = "macos"))]
6-
mod daemon;
7-
8-
#[cfg(any(target_os = "linux", target_os = "macos"))]
9-
mod fuse;
10-
11-
#[cfg(target_os = "macos")]
12-
mod nfs;
13-
141
use clap::{CommandFactory, Parser};
152
use clap_complete::CompleteEnv;
163

17-
use crate::{
18-
cmd::completions::handle_completions,
4+
use agentfs::{
5+
cmd::{self, completions::handle_completions},
6+
get_runtime,
197
parser::{Args, Command, FsCommand},
208
};
219

@@ -27,7 +15,7 @@ fn main() {
2715

2816
match args.command {
2917
Command::Init { id, force, base } => {
30-
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
18+
let rt = get_runtime();
3119
if let Err(e) = rt.block_on(cmd::init::init_database(id, force, base)) {
3220
eprintln!("Error: {}", e);
3321
std::process::exit(1);
@@ -41,7 +29,7 @@ fn main() {
4129
command,
4230
args,
4331
} => {
44-
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
32+
let rt = get_runtime();
4533
if let Err(e) = rt.block_on(cmd::handle_run_command(
4634
allow,
4735
no_default_allows,
@@ -77,14 +65,14 @@ fn main() {
7765
}
7866
}
7967
Command::Diff { id_or_path } => {
80-
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
68+
let rt = get_runtime();
8169
if let Err(e) = rt.block_on(cmd::fs::diff_filesystem(id_or_path)) {
8270
eprintln!("Error: {}", e);
8371
std::process::exit(1);
8472
}
8573
}
8674
Command::Fs { command } => {
87-
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
75+
let rt = get_runtime();
8876
match command {
8977
FsCommand::Ls {
9078
id_or_path,

cli/src/sandbox/overlay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub async fn run_cmd(
116116

117117
// Start FUSE in a separate thread
118118
let fuse_handle = std::thread::spawn(move || {
119-
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
119+
let rt = crate::get_runtime();
120120
crate::fuse::mount(overlay, fuse_opts, rt)
121121
});
122122

0 commit comments

Comments
 (0)