Skip to content

Commit 6b7781e

Browse files
committed
style: cargo fmt, bump to v0.1.6
1 parent f17f041 commit 6b7781e

9 files changed

Lines changed: 184 additions & 64 deletions

File tree

src/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "qtcloud-data-cli"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2024"
55
authors = ["QuantTide Inc. <opensource@quanttide.com>"]
66
description = "量潮数据云 CLI"

src/cli/src/blueprint_core.rs

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ pub fn extract_cue(response: &str) -> String {
113113
for marker in &["```cue", "```CUE", "```"] {
114114
if let Some(start) = response.find(marker) {
115115
let s = start + marker.len();
116-
let e = response[s..].find("```").map(|i| s + i).unwrap_or(response.len());
116+
let e = response[s..]
117+
.find("```")
118+
.map(|i| s + i)
119+
.unwrap_or(response.len());
117120
let code = response[s..e].trim();
118121
if code.contains("package") || code.contains("#Blueprint") {
119122
return code.to_string();
@@ -285,7 +288,8 @@ mod tests {
285288

286289
#[test]
287290
fn test_extract_cue_from_markdown_block() {
288-
let response = "Here is the CUE:\n```cue\npackage blueprints\nx: {name: \"test\"}\n```\nDone.";
291+
let response =
292+
"Here is the CUE:\n```cue\npackage blueprints\nx: {name: \"test\"}\n```\nDone.";
289293
let cue = extract_cue(response);
290294
assert!(cue.contains("package blueprints"));
291295
assert!(!cue.contains("```"));
@@ -309,15 +313,33 @@ mod tests {
309313

310314
#[test]
311315
fn test_render_html_contains_name() {
312-
let html = render_html("test", None, "draft", "2026-01-01", "2026-01-01", "in", "out", &[]);
316+
let html = render_html(
317+
"test",
318+
None,
319+
"draft",
320+
"2026-01-01",
321+
"2026-01-01",
322+
"in",
323+
"out",
324+
&[],
325+
);
313326
assert!(html.contains("<title>test — Blueprint</title>"));
314327
assert!(html.contains("<h1>test</h1>"));
315328
}
316329

317330
#[test]
318331
fn test_render_html_with_steps() {
319332
let steps = [("s1", "a", "b", "do it"), ("s2", "b", "c", "then this")];
320-
let html = render_html("bp", Some("desc"), "confirmed", "t1", "t2", "in", "out", &steps);
333+
let html = render_html(
334+
"bp",
335+
Some("desc"),
336+
"confirmed",
337+
"t1",
338+
"t2",
339+
"in",
340+
"out",
341+
&steps,
342+
);
321343
assert!(html.contains("s1"));
322344
assert!(html.contains("s2"));
323345
assert!(html.contains("do it"));
@@ -344,7 +366,11 @@ mod tests {
344366
let tmp = std::env::temp_dir().join("bp-test-resolve");
345367
let _ = std::fs::remove_dir_all(&tmp);
346368
std::fs::create_dir_all(&tmp).unwrap();
347-
std::fs::write(tmp.join("my-bp.cue"), "package blueprints\n{name: \"test\"}").unwrap();
369+
std::fs::write(
370+
tmp.join("my-bp.cue"),
371+
"package blueprints\n{name: \"test\"}",
372+
)
373+
.unwrap();
348374

349375
let result = resolve_cue_path("my-bp", tmp.to_str().unwrap());
350376
assert!(result.is_some());
@@ -482,7 +508,9 @@ pub fn contract_tables_to_yaml(md_tables: &str) -> (String, String) {
482508
let output_fields = parse_md_table(md_tables, "输出契约");
483509

484510
if !input_fields.is_empty() && input_fields == output_fields {
485-
eprintln!("错误: 输入契约和输出契约解析到相同字段。LLM 可能跳过了 section 标题,请在 prompt 中要求 LLM 输出 ## 输入契约 和 ## 输出契约 标题。");
511+
eprintln!(
512+
"错误: 输入契约和输出契约解析到相同字段。LLM 可能跳过了 section 标题,请在 prompt 中要求 LLM 输出 ## 输入契约 和 ## 输出契约 标题。"
513+
);
486514
std::process::exit(1);
487515
}
488516

@@ -519,8 +547,10 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
519547
found_section = true;
520548
continue;
521549
}
522-
if in_section && line.starts_with('|') && !line.contains("---") && !line.contains("字段名") {
523-
let cells: Vec<String> = line.split('|')
550+
if in_section && line.starts_with('|') && !line.contains("---") && !line.contains("字段名")
551+
{
552+
let cells: Vec<String> = line
553+
.split('|')
524554
.map(|c| c.trim().to_string())
525555
.filter(|c| !c.is_empty())
526556
.collect();
@@ -536,7 +566,8 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
536566
if !found_section {
537567
for line in text.lines() {
538568
if line.starts_with('|') && !line.contains("---") && !line.contains("字段名") {
539-
let cells: Vec<String> = line.split('|')
569+
let cells: Vec<String> = line
570+
.split('|')
540571
.map(|c| c.trim().to_string())
541572
.filter(|c| !c.is_empty())
542573
.collect();
@@ -550,15 +581,23 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
550581
}
551582

552583
fn fields_to_schema_desc(fields: &[Vec<String>]) -> String {
553-
if fields.is_empty() { return "待定义".into(); }
554-
let items: Vec<String> = fields.iter()
555-
.filter_map(|f| f.first().map(|name| format!("{name}: {}", f.get(1).unwrap_or(&"string".into()))))
584+
if fields.is_empty() {
585+
return "待定义".into();
586+
}
587+
let items: Vec<String> = fields
588+
.iter()
589+
.filter_map(|f| {
590+
f.first()
591+
.map(|name| format!("{name}: {}", f.get(1).unwrap_or(&"string".into())))
592+
})
556593
.collect();
557594
format!("{{\n {}\n }}", items.join(",\n "))
558595
}
559596

560597
fn render_contract_md(input: &[Vec<String>], output: &[Vec<String>]) -> String {
561-
let mut md = String::from("## 输入契约\n\n| 字段名 | 类型 | 业务含义 | 约束条件 |\n|--------|------|----------|----------|\n");
598+
let mut md = String::from(
599+
"## 输入契约\n\n| 字段名 | 类型 | 业务含义 | 约束条件 |\n|--------|------|----------|----------|\n",
600+
);
562601
for row in input {
563602
let cells: Vec<&str> = row.iter().map(|c| c.as_str()).collect();
564603
if cells.len() >= 4 {
@@ -613,7 +652,10 @@ pub fn blueprint_table_to_yaml(md_table: &str, project_name: &str) -> (String, S
613652
let deps_yaml = if deps.is_empty() || deps == "-" {
614653
String::new()
615654
} else {
616-
let dep_list: String = deps.split(',').map(|d| format!("\n - {}", d.trim())).collect();
655+
let dep_list: String = deps
656+
.split(',')
657+
.map(|d| format!("\n - {}", d.trim()))
658+
.collect();
617659
format!("\n depends:{}", dep_list)
618660
};
619661

@@ -657,10 +699,14 @@ updated_at: "2026-07-24T00:00:00+00:00"
657699
}
658700

659701
fn render_blueprint_md(name: &str, steps: &[Vec<String>]) -> String {
660-
let mut md = format!("# {name}\n\n## 处理步骤\n\n| 步骤名 | 输入 | 输出 | 处理逻辑 | 依赖 |\n|--------|------|------|----------|------|\n");
702+
let mut md = format!(
703+
"# {name}\n\n## 处理步骤\n\n| 步骤名 | 输入 | 输出 | 处理逻辑 | 依赖 |\n|--------|------|------|----------|------|\n"
704+
);
661705
for row in steps {
662706
let cells: Vec<&str> = row.iter().map(|c| c.as_str()).collect();
663-
let padded: Vec<String> = (0..5).map(|i| cells.get(i).unwrap_or(&"").to_string()).collect();
707+
let padded: Vec<String> = (0..5)
708+
.map(|i| cells.get(i).unwrap_or(&"").to_string())
709+
.collect();
664710
md.push_str(&format!("| {} |\n", padded.join(" | ")));
665711
}
666712
md
@@ -702,7 +748,11 @@ pub fn implement_step_prompt(
702748
from_desc = from_desc,
703749
to_desc = to_desc,
704750
step_desc = step_desc,
705-
prev_section = if prev_functions.is_empty() { "无(这是第一步)" } else { prev_functions },
751+
prev_section = if prev_functions.is_empty() {
752+
"无(这是第一步)"
753+
} else {
754+
prev_functions
755+
},
706756
func_name = to_snake(step_name),
707757
)
708758
}

src/cli/src/contract.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub enum ContractAction {
1919
}
2020

2121
pub fn run(args: &ContractArgs) {
22-
let dir = std::env::var("CONTRACT_DIR").unwrap_or_else(|_| ".quanttide/data/contract".to_string());
22+
let dir =
23+
std::env::var("CONTRACT_DIR").unwrap_or_else(|_| ".quanttide/data/contract".to_string());
2324

2425
match &args.action {
2526
ContractAction::List => {
@@ -37,14 +38,14 @@ pub fn run(args: &ContractArgs) {
3738
&& (name.ends_with(".yaml")
3839
|| name.ends_with(".cue")
3940
|| name.ends_with(".json"))
40-
{
41-
println!(
42-
" - {}",
43-
name.trim_end_matches(".yaml")
44-
.trim_end_matches(".cue")
45-
.trim_end_matches(".json")
46-
);
47-
}
41+
{
42+
println!(
43+
" - {}",
44+
name.trim_end_matches(".yaml")
45+
.trim_end_matches(".cue")
46+
.trim_end_matches(".json")
47+
);
48+
}
4849
}
4950
} else {
5051
eprintln!("{stderr}");
@@ -68,10 +69,11 @@ pub fn run(args: &ContractArgs) {
6869
.args(["export", "--out", "yaml", "--expression", &key, &dir])
6970
.output();
7071
if let Ok(out) = output
71-
&& out.status.success() {
72-
println!("{}", String::from_utf8_lossy(&out.stdout));
73-
return;
74-
}
72+
&& out.status.success()
73+
{
74+
println!("{}", String::from_utf8_lossy(&out.stdout));
75+
return;
76+
}
7577
// 回退:直接读取文件
7678
for ext in &["yaml", "yml", "cue", "json"] {
7779
let path = format!("{dir}/{name}.{ext}");

src/cli/src/design.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ fn cmd_contract(input: &str) {
5454
let llm = quanttide_agent::LLM::default();
5555
let messages = vec![quanttide_agent::Message::new("user", &prompt)];
5656

57-
let stem = Path::new(input).file_stem().unwrap_or_default().to_string_lossy();
57+
let stem = Path::new(input)
58+
.file_stem()
59+
.unwrap_or_default()
60+
.to_string_lossy();
5861
println!("正在从 DRD 生成 Contract: {stem} ...");
5962

6063
match llm.complete(&messages, quanttide_agent::llm::CompleteOptions::default()) {
@@ -77,12 +80,16 @@ fn cmd_blueprint(input: &str) {
7780
let llm = quanttide_agent::LLM::default();
7881
let messages = vec![quanttide_agent::Message::new("user", &prompt)];
7982

80-
let stem = Path::new(input).file_stem().unwrap_or_default().to_string_lossy();
83+
let stem = Path::new(input)
84+
.file_stem()
85+
.unwrap_or_default()
86+
.to_string_lossy();
8187
println!("正在从 DRD 生成 Blueprint: {stem} ...");
8288

8389
match llm.complete(&messages, quanttide_agent::llm::CompleteOptions::default()) {
8490
Ok(resp) => {
85-
let (yaml_content, md_content) = blueprint_core::blueprint_table_to_yaml(&resp.content, &stem);
91+
let (yaml_content, md_content) =
92+
blueprint_core::blueprint_table_to_yaml(&resp.content, &stem);
8693
write_spec_files(&stem, "blueprint", &yaml_content, &md_content);
8794

8895
// Generate HTML preview from YAML
@@ -91,12 +98,28 @@ fn cmd_blueprint(input: &str) {
9198
eprintln!("解析 YAML 失败: {e}");
9299
std::process::exit(1);
93100
});
94-
let step_refs: Vec<(&str, &str, &str, &str)> = bp.pipeline.steps.iter()
95-
.map(|s| (s.name.as_str(), s.from.as_str(), s.to.as_str(), s.desc.as_str()))
101+
let step_refs: Vec<(&str, &str, &str, &str)> = bp
102+
.pipeline
103+
.steps
104+
.iter()
105+
.map(|s| {
106+
(
107+
s.name.as_str(),
108+
s.from.as_str(),
109+
s.to.as_str(),
110+
s.desc.as_str(),
111+
)
112+
})
96113
.collect();
97114
let html = blueprint_core::render_html(
98-
&bp.name, bp.description.as_deref(), bp.status.as_str(),
99-
&bp.created_at, &bp.updated_at, "", "", &step_refs,
115+
&bp.name,
116+
bp.description.as_deref(),
117+
bp.status.as_str(),
118+
&bp.created_at,
119+
&bp.updated_at,
120+
"",
121+
"",
122+
&step_refs,
100123
);
101124
let spec_dir = blueprint_core::spec_dir();
102125
let html_path = Path::new(&spec_dir).join(format!("{stem}-blueprint.html"));
@@ -168,18 +191,34 @@ fn cmd_preview(input: &str, output: &Option<String>) {
168191
std::process::exit(1);
169192
});
170193

171-
let bp: quanttide_data_core::Blueprint = serde_yaml::from_str(&yaml_content)
172-
.unwrap_or_else(|e| {
194+
let bp: quanttide_data_core::Blueprint =
195+
serde_yaml::from_str(&yaml_content).unwrap_or_else(|e| {
173196
eprintln!("解析 YAML 失败: {e}");
174197
std::process::exit(1);
175198
});
176199

177-
let step_refs: Vec<(&str, &str, &str, &str)> = bp.pipeline.steps.iter()
178-
.map(|s| (s.name.as_str(), s.from.as_str(), s.to.as_str(), s.desc.as_str()))
200+
let step_refs: Vec<(&str, &str, &str, &str)> = bp
201+
.pipeline
202+
.steps
203+
.iter()
204+
.map(|s| {
205+
(
206+
s.name.as_str(),
207+
s.from.as_str(),
208+
s.to.as_str(),
209+
s.desc.as_str(),
210+
)
211+
})
179212
.collect();
180213
let html = blueprint_core::render_html(
181-
&bp.name, bp.description.as_deref(), bp.status.as_str(),
182-
&bp.created_at, &bp.updated_at, "", "", &step_refs,
214+
&bp.name,
215+
bp.description.as_deref(),
216+
bp.status.as_str(),
217+
&bp.created_at,
218+
&bp.updated_at,
219+
"",
220+
"",
221+
&step_refs,
183222
);
184223
std::fs::write(&output_path, &html).unwrap_or_else(|e| {
185224
eprintln!("写入 .html 失败: {e}");

src/cli/src/implement.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ fn cmd_implement_python(input: &str, output: &Option<String>) {
3434
std::process::exit(1);
3535
});
3636

37-
let bp: quanttide_data_core::Blueprint = serde_yaml::from_str(&yaml_content)
38-
.unwrap_or_else(|e| {
37+
let bp: quanttide_data_core::Blueprint =
38+
serde_yaml::from_str(&yaml_content).unwrap_or_else(|e| {
3939
eprintln!("解析 YAML 失败: {e}");
4040
std::process::exit(1);
4141
});
@@ -52,7 +52,11 @@ fn cmd_implement_python(input: &str, output: &Option<String>) {
5252
let mut generated_functions = String::new();
5353
let mut prev_signatures = String::new();
5454

55-
println!("正在生成 {} 的 Python 实现 ({} 个步骤)...", bp.name, bp.pipeline.steps.len());
55+
println!(
56+
"正在生成 {} 的 Python 实现 ({} 个步骤)...",
57+
bp.name,
58+
bp.pipeline.steps.len()
59+
);
5660

5761
for (i, step) in bp.pipeline.steps.iter().enumerate() {
5862
let prompt = blueprint_core::implement_step_prompt(
@@ -63,7 +67,12 @@ fn cmd_implement_python(input: &str, output: &Option<String>) {
6367
&prev_signatures,
6468
);
6569

66-
println!(" [{}/{}] 正在生成: {} ...", i + 1, bp.pipeline.steps.len(), step.name);
70+
println!(
71+
" [{}/{}] 正在生成: {} ...",
72+
i + 1,
73+
bp.pipeline.steps.len(),
74+
step.name
75+
);
6776

6877
let messages = vec![quanttide_agent::Message::new("user", &prompt)];
6978
match llm.complete(&messages, quanttide_agent::llm::CompleteOptions::default()) {
@@ -118,7 +127,10 @@ fn extract_python_fn(response: &str) -> String {
118127
for marker in &["```python", "```py", "```"] {
119128
if let Some(start) = response.find(marker) {
120129
let s = start + marker.len();
121-
let e = response[s..].find("```").map(|i| s + i).unwrap_or(response.len());
130+
let e = response[s..]
131+
.find("```")
132+
.map(|i| s + i)
133+
.unwrap_or(response.len());
122134
return response[s..e].trim().to_string();
123135
}
124136
}

src/cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clap::{Parser, Subcommand};
22
use qtcloud_data_cli::{
3-
blueprint, catalog, clarify, contract, design, implement, pipeline, process, review, transfer, version,
3+
blueprint, catalog, clarify, contract, design, implement, pipeline, process, review, transfer,
4+
version,
45
};
56

67
#[derive(Parser)]

0 commit comments

Comments
 (0)