cschanhniem commented on issue #23386:
URL: https://github.com/apache/datafusion/issues/23386#issuecomment-4917563553

   The approach of exporting `main_inner` from the binary into a library 
function is sound. A clean pattern used by other Rust CLIs (e.g., `ripgrep`, 
`fd`):
   
   1. Export `pub fn run_cli(args: Vec<String>, ctx_factory: impl Fn() -> 
SessionContext)` from `datafusion-cli/src/lib.rs`
   2. The factory closure lets callers register UDFs/UDAFs before the REPL 
starts
   3. The current `main.rs` simply calls `run_cli(std::env::args().collect(), 
DefaultSessionContextFactory)`
   4. External projects like geodatafusion call it with their own factory
   
   ```rust
   // lib.rs
   pub fn run_cli<F>(args: Vec<String>, ctx_factory: F) -> Result<()>
   where
       F: Fn() -> SessionContext,
   {
       let ctx = ctx_factory();
       // ... rest of CLI setup using ctx
   }
   ```
   
   This avoids duplicating the 300+ lines of CLI initialization (REPL, PRINT 
options, file dispatch) while giving full UDF/UDAF access. I'd be happy to 
review the PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to