11use std:: fs;
22use std:: io;
33use std:: io:: Read ;
4+ use std:: path:: { Path , PathBuf } ;
45use std:: process;
56
67use anyhow:: { Context , Result } ;
@@ -44,14 +45,15 @@ fn handle_parse_errors(path: &str, tree: &Tree, on_parse_error: &OnParseError) {
4445/// Generate Datalog facts from source code
4546#[ derive( Parser , Debug ) ]
4647#[ command( author, version, about, long_about = None ) ]
47- // TODO(lb): Output directory, default is current directory
48- // #[arg(short, long, default_value = None)]
49- // pub output: Option<String>,
5048pub struct Args {
5149 /// Behavior on parse errors
5250 #[ arg( long, default_value_t = OnParseError :: Warn , value_name = "CHOICE" ) ]
5351 on_parse_error : OnParseError ,
5452
53+ /// Output directory
54+ #[ arg( short, long, default_value = "." , value_name = "OUT_DIR" ) ]
55+ pub output_directory : PathBuf ,
56+
5557 /// Source code to consume; if empty, parse from stdin
5658 #[ arg( value_name = "SRC_FILE" ) ]
5759 pub source_files : Vec < String > ,
@@ -75,13 +77,19 @@ fn stdin_string() -> Result<String> {
7577 Ok ( stdin_str)
7678}
7779
80+ fn create_consumer ( output_directory : & Path ) -> Result < super :: wide:: WideCsvConsumer > {
81+ // TODO(lb): Create consumer based on config
82+ // For now, just use the wide CSV consumer as the default
83+ Ok ( super :: wide:: WideCsvConsumer :: new (
84+ output_directory. join ( "node.csv" ) ,
85+ output_directory. join ( "field.csv" ) ,
86+ output_directory. join ( "child.csv" ) ,
87+ ) ?)
88+ }
89+
7890pub fn main ( language : tree_sitter:: Language ) -> Result < ( ) > {
7991 let args = Args :: parse ( ) ;
80- let mut fc = super :: wide:: WideCsvConsumer :: new (
81- "node.csv" . into ( ) ,
82- "field.csv" . into ( ) ,
83- "child.csv" . into ( ) ,
84- ) ?;
92+ let mut fc = create_consumer ( & args. output_directory ) ?;
8593 if args. source_files . is_empty ( ) {
8694 let content = stdin_string ( ) ?;
8795 let tree = parse ( language, & content) ?;
0 commit comments