| 1 | use std::num::NonZeroUsize; |
| 2 | use std::path::PathBuf; |
| 3 | |
| 4 | use anyhow::Context; |
| 5 | |
| 6 | use crate::flags; |
| 7 | |
| 8 | impl flags::Build { |
| 9 | pub fn run(self) -> anyhow::Result<()> { |
| 10 | let repo = self |
| 11 | .repo |
| 12 | .canonicalize() |
| 13 | .with_context(|| format!("failed to access {}", self.repo.display()))?; |
| 14 | let config = skidder::Config { |
| 15 | repos: vec![skidder::Repo::Local { path: repo }], |
| 16 | index: PathBuf::new(), |
| 17 | verbose: self.verbose, |
| 18 | }; |
| 19 | if let Some(grammar) = self.grammar { |
| 20 | skidder::build_grammar(&config, &grammar, self.force)?; |
| 21 | } else { |
| 22 | skidder::build_all_grammars( |
| 23 | &config, |
| 24 | self.force, |
| 25 | self.threads.and_then(NonZeroUsize::new), |
| 26 | )?; |
| 27 | } |
| 28 | Ok(()) |
| 29 | } |
| 30 | } |