feat(cli): import:html subcommand mapping to the import_html mcp tool

This commit is contained in:
Kayshen-X 2026-07-18 14:16:43 +08:00
parent 21d90a2f25
commit 1fdccd1c3b
3 changed files with 47 additions and 0 deletions

View file

@ -360,6 +360,7 @@ fn command_from_positionals(positionals: &[String], flags: &Flags) -> Result<Com
"layout" => map_layout(flags),
"find-space" => map_find_space(flags),
"import:svg" => map_import_svg(positionals, flags),
"import:html" => map_import_html(positionals, flags),
"import:figma" => figma_cli::map_import_figma(positionals, flags),
"codegen:plan" | "codegen:submit" | "codegen:assemble" | "codegen:clean" => {
codegen_cli::map_codegen(positionals, flags)
@ -698,6 +699,27 @@ fn map_import_svg(positionals: &[String], flags: &Flags) -> Result<Command, Stri
tool_call("import_svg", pairs)
}
fn map_import_html(positionals: &[String], flags: &Flags) -> Result<Command, String> {
let path = required_pos(
positionals,
1,
"Usage: op import:html <file.html> [--x N] [--y N] [--parent P] [--page PAGE]",
)?;
let mut pairs = vec![pair("htmlPath", path)];
for (flag, key) in [
("x", "x"),
("y", "y"),
("parent", "parent"),
("page", "pageId"),
] {
if let Some(value) = flag_value(flags, flag) {
pairs.push(pair(key, value));
}
}
push_file_path(&mut pairs, flags);
tool_call("import_html", pairs)
}
fn generic_tool_call(tool: &str, rest: &[String], flags: &Flags) -> Result<Command, String> {
let mut pairs = Vec::new();
for kv in rest {

View file

@ -706,6 +706,30 @@ fn parse_args_maps_import_figma_to_direct_converter() {
);
}
#[test]
fn import_html_maps_to_tool_call() {
let args = vec![
"import:html".to_string(),
"page.html".to_string(),
"--x".to_string(),
"10".to_string(),
"--page".to_string(),
"p1".to_string(),
];
let parsed = parse_args(&args).expect("parse");
assert_eq!(
parsed.command,
Command::ToolCall {
tool: "import_html".to_string(),
args: vec![
("htmlPath".to_string(), "page.html".to_string()),
("x".to_string(), "10".to_string()),
("pageId".to_string(), "p1".to_string()),
],
}
);
}
#[test]
fn figma_default_out_path_matches_ts_suffix_replacement() {
assert_eq!(figma_default_out_path("checkout.fig"), "checkout.op");

View file

@ -55,6 +55,7 @@ COMMON COMMANDS:
op layout [--parent P] [--depth N] snapshot layout tree
op find-space [--direction D] [--width W] [--height H]
op import:svg <file.svg> [--x N] [--y N] [--parent P] [--page PAGE]
op import:html <file.html> [--x N] [--y N] [--parent P] [--page PAGE]
op import:figma <file.fig> [--out output.op]
op codegen:plan <plan-json|@file|->
op codegen:submit <planId> <chunk-result|@file|->