mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2024-11-14 04:42:02 +01:00
fix(core): Fix async panic on blocking #19
Replaced internal threads with tokio spawn functions
This commit is contained in:
parent
45d6462037
commit
75bc17e57d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -278,6 +278,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"tar",
|
"tar",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -327,6 +328,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"tar",
|
"tar",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -42,3 +42,4 @@ sha2 = "0.10.6"
|
|||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
|
tokio = { version = "1.25.0", features = ["full"] }
|
||||||
|
@ -29,3 +29,4 @@ serde_json = "1.0.93"
|
|||||||
sha2 = "0.10.6"
|
sha2 = "0.10.6"
|
||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
|
tokio = { version = "1.25.0", features = ["full"] }
|
||||||
|
@ -3,7 +3,7 @@ use std::{
|
|||||||
io::{BufRead, BufReader},
|
io::{BufRead, BufReader},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::{Child, Stdio},
|
process::{Child, Stdio},
|
||||||
sync::{mpsc::sync_channel, Arc},
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{config::Config, connect_params::ConnectParams};
|
use crate::{config::Config, connect_params::ConnectParams};
|
||||||
@ -20,12 +20,12 @@ impl CliSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect(
|
pub async fn connect(
|
||||||
&self,
|
&self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
cli_path: &PathBuf,
|
cli_path: &PathBuf,
|
||||||
) -> eyre::Result<(ConnectParams, Child)> {
|
) -> eyre::Result<(ConnectParams, Child)> {
|
||||||
self.inner.connect(config, cli_path)
|
self.inner.connect(config, cli_path).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,13 +33,13 @@ impl CliSession {
|
|||||||
struct InnerCliSession {}
|
struct InnerCliSession {}
|
||||||
|
|
||||||
impl InnerCliSession {
|
impl InnerCliSession {
|
||||||
pub fn connect(
|
pub async fn connect(
|
||||||
&self,
|
&self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
cli_path: &PathBuf,
|
cli_path: &PathBuf,
|
||||||
) -> eyre::Result<(ConnectParams, Child)> {
|
) -> eyre::Result<(ConnectParams, Child)> {
|
||||||
let proc = self.start(config, cli_path)?;
|
let proc = self.start(config, cli_path)?;
|
||||||
let params = self.get_conn(proc)?;
|
let params = self.get_conn(proc).await?;
|
||||||
Ok(params)
|
Ok(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ impl InnerCliSession {
|
|||||||
return Ok(proc);
|
return Ok(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_conn(
|
async fn get_conn(
|
||||||
&self,
|
&self,
|
||||||
mut proc: std::process::Child,
|
mut proc: std::process::Child,
|
||||||
) -> eyre::Result<(ConnectParams, std::process::Child)> {
|
) -> eyre::Result<(ConnectParams, std::process::Child)> {
|
||||||
@ -84,14 +84,14 @@ impl InnerCliSession {
|
|||||||
.take()
|
.take()
|
||||||
.ok_or(eyre::anyhow!("could not acquire stderr from child process"))?;
|
.ok_or(eyre::anyhow!("could not acquire stderr from child process"))?;
|
||||||
|
|
||||||
let (sender, receiver) = sync_channel(1);
|
let (sender, mut receiver) = tokio::sync::mpsc::channel(1);
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
tokio::spawn(async move {
|
||||||
let stdout_bufr = BufReader::new(stdout);
|
let stdout_bufr = BufReader::new(stdout);
|
||||||
for line in stdout_bufr.lines() {
|
for line in stdout_bufr.lines() {
|
||||||
let out = line.as_ref().unwrap();
|
let out = line.as_ref().unwrap();
|
||||||
if let Ok(conn) = serde_json::from_str::<ConnectParams>(&out) {
|
if let Ok(conn) = serde_json::from_str::<ConnectParams>(&out) {
|
||||||
sender.send(conn).unwrap();
|
sender.send(conn).await.unwrap();
|
||||||
}
|
}
|
||||||
if let Ok(line) = line {
|
if let Ok(line) = line {
|
||||||
println!("dagger: {}", line);
|
println!("dagger: {}", line);
|
||||||
@ -99,7 +99,7 @@ impl InnerCliSession {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
std::thread::spawn(|| {
|
tokio::spawn(async move {
|
||||||
let stderr_bufr = BufReader::new(stderr);
|
let stderr_bufr = BufReader::new(stderr);
|
||||||
for line in stderr_bufr.lines() {
|
for line in stderr_bufr.lines() {
|
||||||
if let Ok(line) = line {
|
if let Ok(line) = line {
|
||||||
@ -109,7 +109,7 @@ impl InnerCliSession {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let conn = receiver.recv()?;
|
let conn = receiver.recv().await.ok_or(eyre::anyhow!("could not receive ok signal from dagger-engine"))?;
|
||||||
|
|
||||||
Ok((conn, proc))
|
Ok((conn, proc))
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ impl Downloader {
|
|||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cli(&self) -> eyre::Result<PathBuf> {
|
pub async fn get_cli(&self) -> eyre::Result<PathBuf> {
|
||||||
let version = &self.version;
|
let version = &self.version;
|
||||||
let mut cli_bin_path = self.cache_dir()?;
|
let mut cli_bin_path = self.cache_dir()?;
|
||||||
cli_bin_path.push(format!("{CLI_BIN_PREFIX}{version}"));
|
cli_bin_path.push(format!("{CLI_BIN_PREFIX}{version}"));
|
||||||
@ -129,7 +129,7 @@ impl Downloader {
|
|||||||
|
|
||||||
if !cli_bin_path.exists() {
|
if !cli_bin_path.exists() {
|
||||||
cli_bin_path = self
|
cli_bin_path = self
|
||||||
.download(cli_bin_path)
|
.download(cli_bin_path).await
|
||||||
.context("failed to download CLI from archive")?;
|
.context("failed to download CLI from archive")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +145,8 @@ impl Downloader {
|
|||||||
Ok(cli_bin_path)
|
Ok(cli_bin_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download(&self, path: PathBuf) -> eyre::Result<PathBuf> {
|
async fn download(&self, path: PathBuf) -> eyre::Result<PathBuf> {
|
||||||
let expected_checksum = self.expected_checksum()?;
|
let expected_checksum = self.expected_checksum().await?;
|
||||||
|
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
let actual_hash = self.extract_cli_archive(&mut bytes)?;
|
let actual_hash = self.extract_cli_archive(&mut bytes)?;
|
||||||
@ -165,15 +165,15 @@ impl Downloader {
|
|||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_checksum(&self) -> eyre::Result<String> {
|
async fn expected_checksum(&self) -> eyre::Result<String> {
|
||||||
let archive_url = &self.archive_url();
|
let archive_url = &self.archive_url();
|
||||||
let archive_path = PathBuf::from(&archive_url);
|
let archive_path = PathBuf::from(&archive_url);
|
||||||
let archive_name = archive_path
|
let archive_name = archive_path
|
||||||
.file_name()
|
.file_name()
|
||||||
.ok_or(eyre::anyhow!("could not get file_name from archive_url"))?;
|
.ok_or(eyre::anyhow!("could not get file_name from archive_url"))?;
|
||||||
let resp = reqwest::blocking::get(self.checksum_url())?;
|
let resp = reqwest::get(self.checksum_url()).await?;
|
||||||
let resp = resp.error_for_status()?;
|
let resp = resp.error_for_status()?;
|
||||||
for line in resp.text()?.lines() {
|
for line in resp.text().await?.lines() {
|
||||||
let mut content = line.split_whitespace();
|
let mut content = line.split_whitespace();
|
||||||
let checksum = content
|
let checksum = content
|
||||||
.next()
|
.next()
|
||||||
@ -240,9 +240,9 @@ impl Downloader {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::Downloader;
|
use super::Downloader;
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn download() {
|
async fn download() {
|
||||||
let cli_path = Downloader::new("0.3.10".into()).unwrap().get_cli().unwrap();
|
let cli_path = Downloader::new("0.3.10".into()).unwrap().get_cli().await.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some("dagger-0.3.10"),
|
Some("dagger-0.3.10"),
|
||||||
|
@ -11,17 +11,17 @@ impl Engine {
|
|||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
|
async fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
|
||||||
let cli = Downloader::new("0.3.12".into())?.get_cli()?;
|
let cli = Downloader::new("0.3.12".into())?.get_cli().await?;
|
||||||
|
|
||||||
let cli_session = CliSession::new();
|
let cli_session = CliSession::new();
|
||||||
|
|
||||||
Ok(cli_session.connect(cfg, &cli)?)
|
Ok(cli_session.connect(cfg, &cli).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
|
pub async fn start(&self, cfg: &Config) -> eyre::Result<(ConnectParams, Child)> {
|
||||||
// TODO: Add from existing session as well
|
// TODO: Add from existing session as well
|
||||||
self.from_cli(cfg)
|
self.from_cli(cfg).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ mod tests {
|
|||||||
use super::Engine;
|
use super::Engine;
|
||||||
|
|
||||||
// TODO: these tests potentially have a race condition
|
// TODO: these tests potentially have a race condition
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn engine_can_start() {
|
async fn engine_can_start() {
|
||||||
let engine = Engine::new();
|
let engine = Engine::new();
|
||||||
let params = engine.start(&Config::new(None, None, None, None)).unwrap();
|
let params = engine.start(&Config::new(None, None, None, None)).await.unwrap();
|
||||||
|
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
params.0,
|
params.0,
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use crate::introspection::IntrospectionResponse;
|
use crate::introspection::IntrospectionResponse;
|
||||||
use crate::{config::Config, engine::Engine, session::Session};
|
use crate::{config::Config, engine::Engine, session::Session};
|
||||||
|
|
||||||
pub fn get_schema() -> eyre::Result<IntrospectionResponse> {
|
pub async fn get_schema() -> eyre::Result<IntrospectionResponse> {
|
||||||
let cfg = Config::new(None, None, None, None);
|
let cfg = Config::new(None, None, None, None);
|
||||||
|
|
||||||
//TODO: Implement context for proc
|
//TODO: Implement context for proc
|
||||||
let (conn, _proc) = Engine::new().start(&cfg)?;
|
let (conn, _proc) = Engine::new().start(&cfg).await?;
|
||||||
let session = Session::new();
|
let session = Session::new();
|
||||||
let req_builder = session.start(&cfg, &conn)?;
|
let req_builder = session.start(&cfg, &conn)?;
|
||||||
let schema = session.schema(req_builder)?;
|
let schema = session.schema(req_builder).await?;
|
||||||
|
|
||||||
Ok(schema)
|
Ok(schema)
|
||||||
}
|
}
|
||||||
@ -17,8 +17,8 @@ pub fn get_schema() -> eyre::Result<IntrospectionResponse> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::get_schema;
|
use super::get_schema;
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn can_get_schema() {
|
async fn can_get_schema() {
|
||||||
let _ = get_schema().unwrap();
|
let _ = get_schema().await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use graphql_client::GraphQLQuery;
|
use graphql_client::GraphQLQuery;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
blocking::{Client, RequestBuilder},
|
|
||||||
header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE},
|
header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE},
|
||||||
|
Client, RequestBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{config::Config, connect_params::ConnectParams, introspection::IntrospectionResponse};
|
use crate::{config::Config, connect_params::ConnectParams, introspection::IntrospectionResponse};
|
||||||
@ -37,14 +37,14 @@ impl Session {
|
|||||||
Ok(req_builder)
|
Ok(req_builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn schema(&self, req_builder: RequestBuilder) -> eyre::Result<IntrospectionResponse> {
|
pub async fn schema(&self, req_builder: RequestBuilder) -> eyre::Result<IntrospectionResponse> {
|
||||||
let request_body: graphql_client::QueryBody<()> = graphql_client::QueryBody {
|
let request_body: graphql_client::QueryBody<()> = graphql_client::QueryBody {
|
||||||
variables: (),
|
variables: (),
|
||||||
query: introspection_query::QUERY,
|
query: introspection_query::QUERY,
|
||||||
operation_name: introspection_query::OPERATION_NAME,
|
operation_name: introspection_query::OPERATION_NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = req_builder.json(&request_body).send()?;
|
let res = req_builder.json(&request_body).send().await?;
|
||||||
|
|
||||||
if res.status().is_success() {
|
if res.status().is_success() {
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -52,7 +52,7 @@ impl Session {
|
|||||||
return Err(eyre::anyhow!("server error!"));
|
return Err(eyre::anyhow!("server error!"));
|
||||||
} else {
|
} else {
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let error_message = match res.text() {
|
let error_message = match res.text().await {
|
||||||
Ok(msg) => match serde_json::from_str::<serde_json::Value>(&msg) {
|
Ok(msg) => match serde_json::from_str::<serde_json::Value>(&msg) {
|
||||||
Ok(json) => {
|
Ok(json) => {
|
||||||
format!("HTTP {}\n{}", status, serde_json::to_string_pretty(&json)?)
|
format!("HTTP {}\n{}", status, serde_json::to_string_pretty(&json)?)
|
||||||
@ -64,7 +64,7 @@ impl Session {
|
|||||||
return Err(eyre::anyhow!(error_message));
|
return Err(eyre::anyhow!(error_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
let json: IntrospectionResponse = res.json()?;
|
let json: IntrospectionResponse = res.json().await?;
|
||||||
|
|
||||||
Ok(json)
|
Ok(json)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use dagger_sdk::HostDirectoryOpts;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let host_source_dir = client.host().directory_opts(
|
let host_source_dir = client.host().directory_opts(
|
||||||
"examples/build-the-application/app",
|
"examples/build-the-application/app",
|
||||||
|
@ -2,7 +2,7 @@ use rand::Rng;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let host_source_dir = client.host().directory_opts(
|
let host_source_dir = client.host().directory_opts(
|
||||||
"./examples/caching/app",
|
"./examples/caching/app",
|
||||||
|
@ -4,7 +4,7 @@ use rand::Rng;
|
|||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let context_dir = client
|
let context_dir = client
|
||||||
.host()
|
.host()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let version = client
|
let version = client
|
||||||
.container()
|
.container()
|
||||||
|
@ -3,7 +3,7 @@ use rand::Rng;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let host_source_dir = client.host().directory_opts(
|
let host_source_dir = client.host().directory_opts(
|
||||||
"examples/publish-the-application/app",
|
"examples/publish-the-application/app",
|
||||||
|
@ -3,7 +3,7 @@ use rand::Rng;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
let output = "examples/publish-the-application/app/build";
|
let output = "examples/publish-the-application/app/build";
|
||||||
|
|
||||||
let host_source_dir = client.host().directory_opts(
|
let host_source_dir = client.host().directory_opts(
|
||||||
|
@ -2,7 +2,7 @@ use dagger_sdk::HostDirectoryOpts;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let host_source_dir = client.host().directory_opts(
|
let host_source_dir = client.host().directory_opts(
|
||||||
"examples/test-the-application/app",
|
"examples/test-the-application/app",
|
||||||
|
@ -13,9 +13,9 @@ use crate::querybuilder::query;
|
|||||||
|
|
||||||
pub type DaggerConn = Arc<Query>;
|
pub type DaggerConn = Arc<Query>;
|
||||||
|
|
||||||
pub fn connect() -> eyre::Result<DaggerConn> {
|
pub async fn connect() -> eyre::Result<DaggerConn> {
|
||||||
let cfg = Config::default();
|
let cfg = Config::default();
|
||||||
let (conn, proc) = DaggerEngine::new().start(&cfg)?;
|
let (conn, proc) = DaggerEngine::new().start(&cfg).await?;
|
||||||
|
|
||||||
Ok(Arc::new(Query {
|
Ok(Arc::new(Query {
|
||||||
conn,
|
conn,
|
||||||
@ -44,8 +44,8 @@ pub fn graphql_client(conn: &ConnectParams) -> gql_client::Client {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::connect;
|
use super::connect;
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn test_connect() {
|
async fn test_connect() {
|
||||||
let _ = connect().unwrap();
|
let _ = connect().await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ pub struct SecretId(String);
|
|||||||
pub struct SocketId(String);
|
pub struct SocketId(String);
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||||
pub struct BuildArg {
|
pub struct BuildArg {
|
||||||
pub name: String,
|
|
||||||
pub value: String,
|
pub value: String,
|
||||||
|
pub name: String,
|
||||||
}
|
}
|
||||||
pub struct CacheVolume {
|
pub struct CacheVolume {
|
||||||
pub proc: Arc<Child>,
|
pub proc: Arc<Child>,
|
||||||
|
@ -2,7 +2,7 @@ use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_example_container() {
|
async fn test_example_container() {
|
||||||
let client = connect().unwrap();
|
let client = connect().await.unwrap();
|
||||||
|
|
||||||
let alpine = client.container().from("alpine:3.16.2");
|
let alpine = client.container().from("alpine:3.16.2");
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ impl Cli {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(self, args: &[&str]) -> eyre::Result<()> {
|
pub async fn execute(self, args: &[&str]) -> eyre::Result<()> {
|
||||||
let matches = self.cmd.get_matches_from(args);
|
let matches = self.cmd.get_matches_from(args);
|
||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
Some(("generate", args)) => cli_generate::GenerateCommand::exec(args)?,
|
Some(("generate", args)) => cli_generate::GenerateCommand::exec(args).await?,
|
||||||
_ => eyre::bail!("command missing"),
|
_ => eyre::bail!("command missing"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ impl GenerateCommand {
|
|||||||
clap::Command::new("generate").arg(Arg::new("output").long("output"))
|
clap::Command::new("generate").arg(Arg::new("output").long("output"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(arg_matches: &ArgMatches) -> eyre::Result<()> {
|
pub async fn exec(arg_matches: &ArgMatches) -> eyre::Result<()> {
|
||||||
let cfg = Config::default();
|
let cfg = Config::default();
|
||||||
let (conn, _proc) = Engine::new().start(&cfg)?;
|
let (conn, _proc) = Engine::new().start(&cfg).await?;
|
||||||
let session = Session::new();
|
let session = Session::new();
|
||||||
let req = session.start(&cfg, &conn)?;
|
let req = session.start(&cfg, &conn)?;
|
||||||
let schema = session.schema(req)?;
|
let schema = session.schema(req).await?;
|
||||||
let code = generate(
|
let code = generate(
|
||||||
schema.into_schema().schema.unwrap(),
|
schema.into_schema().schema.unwrap(),
|
||||||
Arc::new(RustGenerator {}),
|
Arc::new(RustGenerator {}),
|
||||||
|
@ -3,14 +3,15 @@ use cli::Cli;
|
|||||||
pub mod cli;
|
pub mod cli;
|
||||||
mod cli_generate;
|
mod cli_generate;
|
||||||
|
|
||||||
fn main() -> eyre::Result<()> {
|
#[tokio::main]
|
||||||
|
async fn main() -> eyre::Result<()> {
|
||||||
color_eyre::install().unwrap();
|
color_eyre::install().unwrap();
|
||||||
|
|
||||||
let args = std::env::args();
|
let args = std::env::args();
|
||||||
let args = args.collect::<Vec<String>>();
|
let args = args.collect::<Vec<String>>();
|
||||||
let args = args.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
|
let args = args.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
|
||||||
|
|
||||||
Cli::new()?.execute(args.as_slice())?;
|
Cli::new()?.execute(args.as_slice()).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user