|
6 | 6 | // ------------------------------------------------------------------------------------------------ |
7 | 7 |
|
8 | 8 | use anyhow::anyhow; |
9 | | -use clap::{Parser, ValueEnum}; |
| 9 | +use clap::Parser; |
10 | 10 | use tree_sitter_stack_graphs::cli::database::default_user_database_path_for_crate; |
11 | 11 | use tree_sitter_stack_graphs::cli::provided_languages::Subcommands; |
12 | | -use tree_sitter_stack_graphs::loader::{LanguageConfiguration, LoadError}; |
13 | 12 | use tree_sitter_stack_graphs::NoCancellation; |
14 | 13 |
|
15 | | -/// Flag to select the dialect of the language |
16 | | -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] |
17 | | -pub enum Dialect { |
18 | | - Typescript, |
19 | | - TSX, |
20 | | -} |
21 | | - |
22 | 14 | fn main() -> anyhow::Result<()> { |
23 | 15 | let cli = Cli::parse(); |
24 | | - let lc = match language_configuration(cli.dialect) { |
25 | | - Ok(lc) => lc, |
26 | | - Err(err) => { |
27 | | - eprintln!("{}", err.display_pretty()); |
28 | | - return Err(anyhow!("Language configuration error")); |
29 | | - } |
30 | | - }; |
31 | | - let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?; |
32 | | - cli.subcommand.run(default_db_path, vec![lc]) |
33 | | -} |
34 | | - |
35 | | -fn language_configuration<'a>(dialect: Dialect) -> Result<LanguageConfiguration, LoadError<'a>> { |
36 | | - match dialect { |
37 | | - Dialect::Typescript => { |
38 | | - tree_sitter_stack_graphs_typescript::try_language_configuration_typescript( |
39 | | - &NoCancellation, |
40 | | - ) |
41 | | - } |
42 | | - Dialect::TSX => { |
43 | | - tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation) |
44 | | - } |
| 16 | + let mut lcs = Vec::new(); |
| 17 | + for r in [ |
| 18 | + tree_sitter_stack_graphs_typescript::try_language_configuration_typescript(&NoCancellation), |
| 19 | + tree_sitter_stack_graphs_typescript::try_language_configuration_tsx(&NoCancellation), |
| 20 | + ] { |
| 21 | + let lc = match r { |
| 22 | + Ok(lc) => lc, |
| 23 | + Err(err) => { |
| 24 | + eprintln!("{}", err.display_pretty()); |
| 25 | + return Err(anyhow!("Language configuration error")); |
| 26 | + } |
| 27 | + }; |
| 28 | + lcs.push(lc); |
45 | 29 | } |
| 30 | + let default_db_path = default_user_database_path_for_crate(env!("CARGO_PKG_NAME"))?; |
| 31 | + cli.subcommand.run(default_db_path, lcs) |
46 | 32 | } |
47 | 33 |
|
48 | 34 | #[derive(Parser)] |
49 | 35 | #[clap(about, version)] |
50 | 36 | pub struct Cli { |
51 | | - #[clap( |
52 | | - short, |
53 | | - long, |
54 | | - value_enum, |
55 | | - default_value_t = Dialect::Typescript, |
56 | | - )] |
57 | | - dialect: Dialect, |
58 | | - |
59 | 37 | #[clap(subcommand)] |
60 | 38 | subcommand: Subcommands, |
61 | 39 | } |
0 commit comments