Skip to content

Commit f69389e

Browse files
committed
refactor: rename dts2-extern command to bindgen
- Rename command from dts2-extern to bindgen for better clarity - Update all references throughout the codebase: - Rename files: dts2extern.rs → bindgen.rs - Rename struct: Dts2ExternCommand → BindgenCommand - Update CLI command: dts2-extern → bindgen - Update user agent string to husk-bindgen/0.1.1 - Update documentation and examples - All tests passing (610 total)
1 parent a640a8a commit f69389e

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

examples/fs-example/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Node.js fs Module Example
22

3-
This example demonstrates how to use Node.js's `fs` module from Husk using extern type declarations generated by the `dts2-extern` command.
3+
This example demonstrates how to use Node.js's `fs` module from Husk using extern type declarations generated by the `bindgen` command.
44

55
## How this example was created
66

@@ -12,7 +12,7 @@ This example demonstrates how to use Node.js's `fs` module from Husk using exter
1212
2. Converted the Node.js fs type definitions directly from a URL:
1313
```bash
1414
cd fs-example
15-
husk dts2-extern https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/node/fs.d.ts -o src/fs-types.husk
15+
husk bindgen https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/node/fs.d.ts -o src/fs-types.husk
1616
```
1717

1818
This generated a complete `fs-types.husk` file with all the extern declarations needed to use the fs module.
@@ -71,7 +71,7 @@ cargo run -- build && node add-bindings.js && node dist/main.js
7171

7272
## Key takeaways
7373

74-
- The `dts2-extern` command can convert TypeScript declaration files directly from URLs
74+
- The `bindgen` command can convert TypeScript declaration files directly from URLs
7575
- The generated extern declarations provide type-safe access to JavaScript libraries
7676
- Complex Node.js APIs like the fs module work seamlessly with Husk
7777
- The full fs API is available, not just a simplified subset

src/commands/dts2extern.rs renamed to src/commands/bindgen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) fn create_secure_client() -> Result<reqwest::blocking::Client> {
8888
reqwest::blocking::Client::builder()
8989
.timeout(Duration::from_secs(30)) // 30 second timeout
9090
.redirect(reqwest::redirect::Policy::limited(3)) // Limit redirects to prevent redirect loops
91-
.user_agent("husk-dts2extern/0.1.1") // Proper user agent
91+
.user_agent("husk-bindgen/0.1.1") // Proper user agent
9292
.build()
9393
.context("Failed to create HTTP client")
9494
}
@@ -129,7 +129,7 @@ fn validate_response(response: &reqwest::blocking::Response) -> Result<()> {
129129
}
130130

131131
#[derive(Debug, Args)]
132-
pub struct Dts2ExternCommand {
132+
pub struct BindgenCommand {
133133
/// Input .d.ts file path or URL
134134
input: String,
135135

@@ -150,7 +150,7 @@ pub struct Dts2ExternCommand {
150150
filter: Option<String>,
151151
}
152152

153-
impl Dts2ExternCommand {
153+
impl BindgenCommand {
154154
pub fn execute(&self) -> Result<()> {
155155
// Check if input is a URL
156156
let (content, filename) = if self.input.starts_with("http://")

src/commands/dts2extern_security_tests.rs renamed to src/commands/bindgen_security_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(test)]
2-
mod dts2extern_security_tests {
3-
use super::super::dts2extern::{create_secure_client, validate_url};
2+
mod bindgen_security_tests {
3+
use super::super::bindgen::{create_secure_client, validate_url};
44

55
#[test]
66
fn test_validate_url_allows_https() {

src/commands/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pub mod dts2extern;
1+
pub mod bindgen;
22

33
#[cfg(test)]
4-
mod dts2extern_security_tests;
4+
mod bindgen_security_tests;
55

6-
pub use dts2extern::Dts2ExternCommand;
6+
pub use bindgen::BindgenCommand;

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clap::{Parser, Subcommand};
44
use husk_lang::repl;
55

66
mod commands;
7-
use commands::Dts2ExternCommand;
7+
use commands::BindgenCommand;
88

99
#[derive(Parser, Debug)]
1010
#[command(author, version, about, long_about = None)]
@@ -110,8 +110,8 @@ enum Command {
110110
/// Run tests
111111
Test(Test),
112112

113-
/// Convert TypeScript .d.ts file to Husk extern declarations
114-
Dts2Extern(Dts2ExternCommand),
113+
/// Generate Husk bindings from TypeScript .d.ts files
114+
Bindgen(BindgenCommand),
115115
}
116116

117117
#[derive(Parser, Debug)]
@@ -134,7 +134,7 @@ fn main() -> anyhow::Result<()> {
134134
Some(Command::Build(build)) => build_command(build, no_color)?,
135135
Some(Command::New(new)) => new_command(new)?,
136136
Some(Command::Test(test)) => test_command(test, no_color)?,
137-
Some(Command::Dts2Extern(dts2extern)) => dts2extern.execute()?,
137+
Some(Command::Bindgen(bindgen)) => bindgen.execute()?,
138138
Some(Command::Repl) | None => repl()?,
139139
};
140140
Ok(())

tests/dts2extern_error_test.rs renamed to tests/bindgen_error_test.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::io::Write;
22
use std::process::Command;
33
use tempfile::NamedTempFile;
44

5-
// Helper to run dts2extern command
6-
fn run_dts2extern(args: &[&str]) -> std::process::Output {
7-
let mut cmd_args = vec!["run", "-q", "--", "dts2-extern"];
5+
// Helper to run bindgen command
6+
fn run_bindgen(args: &[&str]) -> std::process::Output {
7+
let mut cmd_args = vec!["run", "-q", "--", "bindgen"];
88
cmd_args.extend_from_slice(args);
99

1010
Command::new("cargo")
@@ -22,7 +22,7 @@ fn create_temp_file(content: &str, suffix: &str) -> NamedTempFile {
2222

2323
#[test]
2424
fn test_non_existent_file() {
25-
let output = run_dts2extern(&["/path/that/does/not/exist.d.ts"]);
25+
let output = run_bindgen(&["/path/that/does/not/exist.d.ts"]);
2626

2727
if output.status.success() {
2828
eprintln!("Expected failure for non-existent file, but got success");
@@ -46,7 +46,7 @@ fn test_non_existent_file() {
4646
fn test_non_dts_extension() {
4747
let file = create_temp_file("export function test(): void;", ".ts");
4848

49-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
49+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
5050

5151
assert!(!output.status.success());
5252
let stderr = String::from_utf8_lossy(&output.stderr);
@@ -58,7 +58,7 @@ fn test_non_dts_extension() {
5858
fn test_empty_file() {
5959
let file = create_temp_file("", ".d.ts");
6060

61-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
61+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
6262

6363
// Empty file should succeed
6464
assert!(output.status.success());
@@ -71,7 +71,7 @@ fn test_invalid_typescript_syntax() {
7171
".d.ts",
7272
);
7373

74-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
74+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
7575

7676
assert!(!output.status.success());
7777
let stderr = String::from_utf8_lossy(&output.stderr);
@@ -92,7 +92,7 @@ fn test_malformed_type_declarations() {
9292
".d.ts",
9393
);
9494

95-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
95+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
9696

9797
assert!(!output.status.success());
9898
}
@@ -108,7 +108,7 @@ fn test_circular_type_reference() {
108108
".d.ts",
109109
);
110110

111-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
111+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
112112

113113
// Should handle circular references gracefully
114114
assert!(output.status.success());
@@ -128,7 +128,7 @@ fn test_reserved_keyword_parameter_names() {
128128
".d.ts",
129129
);
130130

131-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
131+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
132132

133133
// Should handle reserved keywords
134134
assert!(output.status.success());
@@ -141,7 +141,7 @@ fn test_reserved_keyword_parameter_names() {
141141
fn test_output_to_readonly_directory() {
142142
let file = create_temp_file("export function test(): void;", ".d.ts");
143143

144-
let output = run_dts2extern(&[
144+
let output = run_bindgen(&[
145145
file.path().to_str().unwrap(),
146146
"-o",
147147
"/root/readonly_output.husk",
@@ -168,7 +168,7 @@ fn test_filter_with_no_matches() {
168168
".d.ts",
169169
);
170170

171-
let output = run_dts2extern(&[file.path().to_str().unwrap(), "--filter", "nonexistent.*"]);
171+
let output = run_bindgen(&[file.path().to_str().unwrap(), "--filter", "nonexistent.*"]);
172172

173173
// Should succeed but produce module with no exports
174174
assert!(output.status.success());
@@ -178,7 +178,7 @@ fn test_filter_with_no_matches() {
178178
fn test_invalid_regex_filter() {
179179
let file = create_temp_file("export function test(): void;", ".d.ts");
180180

181-
let output = run_dts2extern(&[file.path().to_str().unwrap(), "--filter", "[invalid(regex"]);
181+
let output = run_bindgen(&[file.path().to_str().unwrap(), "--filter", "[invalid(regex"]);
182182

183183
// TODO: Filter validation is not yet implemented
184184
// For now, the command succeeds even with invalid regex
@@ -202,7 +202,7 @@ fn test_no_exports_in_file() {
202202
".d.ts",
203203
);
204204

205-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
205+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
206206

207207
// Should succeed
208208
assert!(output.status.success());
@@ -220,7 +220,7 @@ fn test_namespace_only_declarations() {
220220
".d.ts",
221221
);
222222

223-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
223+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
224224

225225
// Should handle namespace-only files
226226
assert!(output.status.success());
@@ -237,7 +237,7 @@ fn test_complex_generic_types_with_simplify() {
237237
".d.ts",
238238
);
239239

240-
let output = run_dts2extern(&[file.path().to_str().unwrap(), "--simplify"]);
240+
let output = run_bindgen(&[file.path().to_str().unwrap(), "--simplify"]);
241241

242242
// With simplify, should succeed
243243
assert!(output.status.success());
@@ -250,7 +250,7 @@ fn test_complex_generic_types_with_simplify() {
250250
fn test_module_name_with_special_chars() {
251251
let file = create_temp_file("export function test(): void;", ".d.ts");
252252

253-
let output = run_dts2extern(&[file.path().to_str().unwrap(), "-m", "[email protected]"]);
253+
let output = run_bindgen(&[file.path().to_str().unwrap(), "-m", "[email protected]"]);
254254

255255
// Module names with special characters should be handled
256256
assert!(output.status.success());
@@ -261,7 +261,7 @@ fn test_very_long_module_name() {
261261
let file = create_temp_file("export function test(): void;", ".d.ts");
262262

263263
let very_long_name = "a".repeat(1000);
264-
let output = run_dts2extern(&[file.path().to_str().unwrap(), "-m", &very_long_name]);
264+
let output = run_bindgen(&[file.path().to_str().unwrap(), "-m", &very_long_name]);
265265

266266
// Should handle very long module names
267267
assert!(output.status.success());
@@ -275,7 +275,7 @@ fn test_binary_file_input() {
275275
.unwrap();
276276
file.flush().unwrap();
277277

278-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
278+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
279279

280280
assert!(!output.status.success());
281281
}
@@ -288,7 +288,7 @@ fn test_file_with_bom() {
288288
file.write_all(b"export function test(): void;").unwrap();
289289
file.flush().unwrap();
290290

291-
let output = run_dts2extern(&[file.path().to_str().unwrap()]);
291+
let output = run_bindgen(&[file.path().to_str().unwrap()]);
292292

293293
// Should handle BOM correctly
294294
assert!(output.status.success());

0 commit comments

Comments
 (0)