Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 9b0ec3c

Browse files
committed
chore: add simple example
(again)
1 parent b00c8c1 commit 9b0ec3c

3 files changed

Lines changed: 225 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 179 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ serde_json = "1.0.81"
2828
typescript_tools = "9.0.0"
2929

3030
[dev-dependencies]
31-
env_logger = { version = "0.10.0", default-features = false }
31+
clap = { version = "4.4.4", features = ["derive"] }

examples/simple.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use std::io::{self, Write};
2+
use std::path::PathBuf;
3+
4+
use clap::{Parser, ValueEnum};
5+
use tsconfig_includes::{estimate, exact};
6+
7+
#[derive(Clone, Debug, ValueEnum)]
8+
enum EnumerationMethod {
9+
Estimate,
10+
Exact,
11+
}
12+
13+
#[derive(Debug, Parser)]
14+
struct Cli {
15+
/// Which enumeration method to use
16+
#[arg(long, value_enum)]
17+
pub enumeration_method: EnumerationMethod,
18+
19+
/// Path to monorepo root directory
20+
#[arg(long)]
21+
pub monorepo_root: PathBuf,
22+
23+
/// List of tsconfig files to enumerate dependencies of
24+
#[arg()]
25+
pub tsconfig_files: Vec<PathBuf>,
26+
}
27+
28+
fn main() -> Result<(), Box<dyn std::error::Error>> {
29+
let cli = Cli::parse();
30+
31+
match cli.enumeration_method {
32+
EnumerationMethod::Estimate => {
33+
let result =
34+
estimate::tsconfig_includes_by_package_name(cli.monorepo_root, cli.tsconfig_files)?;
35+
writeln!(io::stdout(), "{}", serde_json::to_string_pretty(&result)?)?;
36+
}
37+
EnumerationMethod::Exact => {
38+
let result =
39+
exact::tsconfig_includes_by_package_name(cli.monorepo_root, cli.tsconfig_files)?;
40+
writeln!(io::stdout(), "{}", serde_json::to_string_pretty(&result)?)?;
41+
}
42+
};
43+
44+
Ok(())
45+
}

0 commit comments

Comments
 (0)