with type filtering

This commit is contained in:
Kasper Juul Hermansen 2023-01-28 20:21:19 +01:00
parent 3eb891422f
commit 2eb5d98c8a
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
8 changed files with 4763 additions and 4 deletions

View File

@ -5,3 +5,11 @@ A dagger sdk written in rust for rust.
## Disclaimer ## Disclaimer
Work in progress. This is not ready for usage yet Work in progress. This is not ready for usage yet
### Status
- [x] dagger cli downloader
- [x] dagger network session
- [ ] graphql rust codegen (User API)
- [ ] fix build / release cycle
- [ ] general api stabilisation

View File

@ -1,3 +1,5 @@
use crate::cli_generate;
pub struct Cli { pub struct Cli {
cmd: clap::Command, cmd: clap::Command,
} }
@ -7,7 +9,7 @@ impl Cli {
Ok(Self { Ok(Self {
cmd: clap::Command::new("dagger-rust") cmd: clap::Command::new("dagger-rust")
.subcommand_required(true) .subcommand_required(true)
.subcommand(clap::Command::new("generate")), .subcommand(cli_generate::GenerateCommand::new_cmd()),
}) })
} }
@ -15,8 +17,10 @@ impl Cli {
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)) => Ok(()), Some(("generate", args)) => cli_generate::GenerateCommand::exec(args)?,
_ => eyre::bail!("command missing"), _ => eyre::bail!("command missing"),
} }
Ok(())
} }
} }

30
src/cli_generate.rs Normal file
View File

@ -0,0 +1,30 @@
use clap::{Arg, ArgMatches};
use crate::{code_generation::CodeGeneration, config::Config, engine::Engine, session::Session};
#[allow(dead_code)]
pub struct GenerateCommand;
#[allow(dead_code)]
impl GenerateCommand {
pub fn new_cmd() -> clap::Command {
clap::Command::new("generate").arg(Arg::new("output").long("output"))
}
pub fn exec(arg_matches: &ArgMatches) -> eyre::Result<()> {
let cfg = Config::default();
let (conn, _proc) = Engine::new().start(&cfg)?;
let session = Session::new();
let req = session.start(&cfg, &conn)?;
let schema = session.schema(req)?;
let code = CodeGeneration::generate(&schema)?;
if let Some(output) = arg_matches.get_one::<String>("output") {
// TODO: Write to file
} else {
println!("{}", code);
}
Ok(())
}
}

4709
src/code_generation.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,12 @@ pub struct Config {
pub execute_timeout_ms: Option<u64>, pub execute_timeout_ms: Option<u64>,
} }
impl Default for Config {
fn default() -> Self {
Self::new(None, None, None, None)
}
}
impl Config { impl Config {
pub fn new( pub fn new(
workdir_path: Option<PathBuf>, workdir_path: Option<PathBuf>,

View File

@ -1,5 +1,7 @@
pub mod cli; pub mod cli;
mod cli_generate;
mod cli_session; mod cli_session;
mod code_generation;
mod config; mod config;
mod connect_params; mod connect_params;
pub mod dagger; pub mod dagger;

View File

@ -8,7 +8,7 @@ pub fn get_schema() -> eyre::Result<IntrospectionResponse> {
//TODO: Implement context for proc //TODO: Implement context for proc
let (conn, _proc) = Engine::new().start(&cfg)?; let (conn, _proc) = Engine::new().start(&cfg)?;
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)?;
Ok(schema) Ok(schema)

View File

@ -23,7 +23,7 @@ impl Session {
Self {} Self {}
} }
pub fn start(&self, _cfg: Config, conn: &ConnectParams) -> eyre::Result<RequestBuilder> { pub fn start(&self, _cfg: &Config, conn: &ConnectParams) -> eyre::Result<RequestBuilder> {
let client = Client::builder() let client = Client::builder()
.user_agent("graphql-rust/0.10.0") .user_agent("graphql-rust/0.10.0")
.connection_verbose(true) .connection_verbose(true)