Skip to content

Commit 549baa5

Browse files
committed
Apply module template updates
1 parent aa5bd1a commit 549baa5

4 files changed

Lines changed: 100 additions & 51 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,52 @@ repository = "https://github.com/asimov-modules/asimov-brightdata-module"
1414
license = "Unlicense"
1515
keywords = ["asimov-module", "asimov", "ai"]
1616
categories = [
17-
"command-line-utilities",
18-
"api-bindings",
19-
"web-programming::http-client",
20-
"text-processing",
17+
"command-line-utilities",
18+
"api-bindings",
19+
"web-programming::http-client",
20+
"text-processing",
2121
]
2222
publish = true
2323

2424
[features]
2525
default = ["all", "cli", "std"]
2626
all = ["tracing"]
27-
cli = ["pretty", "dep:clientele"]
27+
cli = ["asimov-module/cli", "pretty", "dep:clap", "dep:clientele"]
2828
pretty = ["dep:colored_json"]
2929
std = [
30-
"asimov-module/std",
31-
"clientele/std",
32-
"jq/std",
33-
"serde/std",
34-
"tracing-subscriber?/fmt",
35-
"tracing-subscriber?/std",
30+
"asimov-module/std",
31+
"clap?/std",
32+
"clientele?/std",
33+
"jq/std",
34+
"serde/std",
35+
"tracing-subscriber?/fmt",
36+
"tracing-subscriber?/std",
3637
]
37-
tracing = ["dep:tracing-subscriber"]
38+
tracing = ["asimov-module/tracing", "dep:tracing-subscriber"]
3839
unstable = []
3940

4041
[dependencies]
4142
asimov-module = { version = "25.0.0-dev.21", default-features = false, features = [
42-
"serde",
43+
"serde",
4344
] }
45+
clap = { version = "4.5", default-features = false, optional = true }
4446
clientele = { version = "0.3", default-features = false, features = [
45-
"argfile",
46-
"dotenv",
47-
"wild",
47+
"argfile",
48+
"dotenv",
49+
"wild",
4850
], optional = true }
4951
colored_json = { version = "5", default-features = false, optional = true }
5052
jq = { version = "0.1", default-features = false, features = ["all"] }
5153
serde = { version = "1", default-features = false, features = ["derive"] }
5254
serde_json = { version = "1", default-features = false, features = ["alloc"] }
5355
tracing-subscriber = { version = "0.3", default-features = false, features = [
54-
"alloc",
55-
"tracing-log",
56+
"alloc",
57+
"tracing-log",
5658
], optional = true }
5759
ureq = { version = "3.0", default-features = false, features = [
58-
"platform-verifier",
59-
"rustls",
60-
"json",
60+
"platform-verifier",
61+
"rustls",
62+
"json",
6163
] }
6264

6365
[profile.release]

src/fetcher/main.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// This is free and unencumbered software released into the public domain.
22

3+
use clap::Parser;
4+
use clientele::StandardOptions;
5+
6+
/// asimov-brightdata-fetcher
7+
#[derive(Debug, Parser)]
8+
#[command(arg_required_else_help = true)]
9+
struct Options {
10+
#[clap(flatten)]
11+
flags: StandardOptions,
12+
13+
/// The output format.
14+
#[arg(value_name = "FORMAT", short = 'o', long)]
15+
output: Option<String>,
16+
17+
urls: Vec<String>,
18+
}
19+
320
#[cfg(feature = "std")]
421
fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
522
use asimov_brightdata_module::{
@@ -13,22 +30,28 @@ fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
1330
clientele::dotenv().ok();
1431

1532
// Expand wildcards and @argfiles:
16-
let args = clientele::args_os()?;
33+
let args = asimov_module::args_os()?;
34+
35+
// Parse command-line options:
36+
let options = Options::parse_from(args);
1737

18-
// Configure logging:
38+
// Handle the `--version` flag:
39+
if options.flags.version {
40+
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
41+
return Ok(EX_OK);
42+
}
43+
44+
// Handle the `--license` flag:
45+
if options.flags.license {
46+
print!("{}", include_str!("../../UNLICENSE"));
47+
return Ok(EX_OK);
48+
}
49+
50+
// Configure logging & tracing:
1951
#[cfg(feature = "tracing")]
20-
tracing_subscriber::fmt()
21-
.with_writer(std::io::stderr)
22-
.with_max_level(tracing_subscriber::filter::LevelFilter::WARN)
23-
.init();
24-
25-
// Parse URLs from command-line arguments:
26-
let urls: Vec<String> = args
27-
.iter()
28-
.skip(1)
29-
.map(|arg| String::from_str(&arg.to_string_lossy()).unwrap())
30-
.collect();
31-
if urls.is_empty() {
52+
asimov_module::init_tracing_subscriber(&options.flags).expect("failed to initialize logging");
53+
54+
if options.urls.is_empty() {
3255
return Ok(EX_OK);
3356
}
3457

@@ -48,7 +71,7 @@ fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
4871
let api = BrightData::new(api_key.into());
4972

5073
// Process each of the given URL arguments:
51-
for url in urls {
74+
for url in options.urls {
5275
// Find the appropriate dataset ID based on the URL prefix:
5376
let Some(dataset) = find_dataset_for(&url) else {
5477
return Ok(EX_UNAVAILABLE); // not supported

src/importer/main.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// This is free and unencumbered software released into the public domain.
22

3+
use clap::Parser;
4+
use clientele::StandardOptions;
5+
6+
/// asimov-brightdata-importer
7+
#[derive(Debug, Parser)]
8+
#[command(arg_required_else_help = true)]
9+
struct Options {
10+
#[clap(flatten)]
11+
flags: StandardOptions,
12+
13+
/// The output format.
14+
#[arg(value_name = "FORMAT", short = 'o', long)]
15+
output: Option<String>,
16+
17+
urls: Vec<String>,
18+
}
19+
320
#[cfg(feature = "std")]
421
fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
522
use asimov_brightdata_module::{
@@ -13,22 +30,28 @@ fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
1330
clientele::dotenv().ok();
1431

1532
// Expand wildcards and @argfiles:
16-
let args = clientele::args_os()?;
33+
let args = asimov_module::args_os()?;
34+
35+
// Parse command-line options:
36+
let options = Options::parse_from(args);
1737

18-
// Configure logging:
38+
// Handle the `--version` flag:
39+
if options.flags.version {
40+
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
41+
return Ok(EX_OK);
42+
}
43+
44+
// Handle the `--license` flag:
45+
if options.flags.license {
46+
print!("{}", include_str!("../../UNLICENSE"));
47+
return Ok(EX_OK);
48+
}
49+
50+
// Configure logging & tracing:
1951
#[cfg(feature = "tracing")]
20-
tracing_subscriber::fmt()
21-
.with_writer(std::io::stderr)
22-
.with_max_level(tracing_subscriber::filter::LevelFilter::WARN)
23-
.init();
24-
25-
// Parse URLs from command-line arguments:
26-
let urls: Vec<String> = args
27-
.iter()
28-
.skip(1)
29-
.map(|arg| String::from_str(&arg.to_string_lossy()).unwrap())
30-
.collect();
31-
if urls.is_empty() {
52+
asimov_module::init_tracing_subscriber(&options.flags).expect("failed to initialize logging");
53+
54+
if options.urls.is_empty() {
3255
return Ok(EX_OK);
3356
}
3457

@@ -48,7 +71,7 @@ fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
4871
let api = BrightData::new(api_key.into());
4972

5073
// Process each of the given URL arguments:
51-
for url in urls {
74+
for url in options.urls {
5275
// Find the appropriate dataset ID based on the URL prefix:
5376
let Some(dataset) = find_dataset_for(&url) else {
5477
return Ok(EX_UNAVAILABLE); // not supported

0 commit comments

Comments
 (0)