Skip to content

Commit 7b5d967

Browse files
Merge pull request #29 from code0-tech/20-download-command
Add Download Command
2 parents ea870b2 + 6a8c982 commit 7b5d967

File tree

11 files changed

+2078
-262
lines changed

11 files changed

+2078
-262
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ edition = "2024"
1010
serde = "1.0.219"
1111
serde_json = "1.0.140"
1212
tucana = "0.0.32"
13-
clap = { version = "4.5.41" }
13+
clap = "4.5.41"
1414
colored = "2.0"
1515
tabled = "0.15"
1616
notify = "6.0"
17+
reqwest = "0.12.22"
18+
tokio = "1.47.0"
19+
futures = "0.3.31"
20+
zip = "4.3.0"
21+
bytes = "1.10.1"
1722

1823
[workspace.dependencies.code0-definition-reader]
1924
path = "../code0-definition/reader/rust"

README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Definitions
2+
This repository contains all definitions for Code0. These definitions will be used to create a Flow. It also contains a CLI tool for managing definitions and a reader for reading all definitions.
23

34
## Definition CLI
45

@@ -7,27 +8,46 @@
78

89
### Usage
910
(Stay inside the root directory when running the command)
10-
### General Report
11+
12+
#### Download
13+
Will download the latest Definitions from the Code0 Definition Repository.
14+
15+
If no feature is specified, all features will be downloaded. If a feature is specified, only that feature will be kept & can be loaded by one of the following languages: TypeScript, Rust.
16+
17+
```bash
18+
./cargo run download
19+
./cargo run download -f feature_1 feature_2 feature_3
20+
```
21+
22+
#### General Report
23+
Will create a report of all errors in the definitions.
24+
1125
```bash
1226
./cargo run report
1327
./cargo run report -p /path/to/definitions
1428
```
1529

16-
### Feature Report
30+
#### Feature Report
31+
Will create a report of all errors in the definitions for a specific feature. Will also report on all specified functions, data types, and flow types.
32+
1733
```bash
1834
./cargo run feature
1935
./cargo run feature -p /path/to/definitions
2036
./cargo run feature -f feature_name
2137
./cargo run feature -f feature_name -p /path/to/definitions
2238
```
2339

24-
### Watch for Changes
40+
#### Watch for Changes
41+
Will run the report each time a definition file changes.
42+
2543
```bash
2644
./cargo run watch
2745
./cargo run watch -p /path/to/definitions
2846
```
2947

30-
### Definition
48+
#### Definition
49+
Will search for a specific definition.
50+
3151
```bash
3252
./cargo run definition -n definition_name
3353
./cargo run definition -n definition_name -p /path/to/definitions
@@ -53,3 +73,24 @@ for (const feature in features) {
5373
}
5474
```
5575

76+
## Rust Definition Package
77+
78+
### Install Package
79+
```bash
80+
cargo add code0-definition-reader
81+
```
82+
83+
### Usage
84+
85+
```rs
86+
use code0_definition_reader::Definition;
87+
88+
let features = Definition::new("./path/to/definitions");
89+
90+
for feature in features {
91+
let name = feature.name(); //name of the feature (e.g. rest)
92+
let data_types = feature.data_types(); //dataTypes of this feature
93+
let flow_types = feature.flow_types(); //flowTypes of this feature
94+
let functions = feature.runtime_functions(); //runtimeFunctions of this feature
95+
}
96+
```

cli/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ colored = { workspace = true }
1111
tabled = { workspace = true }
1212
notify = { workspace = true }
1313
serde_json = { workspace = true }
14+
reqwest = { workspace = true, features = ["json", "stream"] }
15+
serde = { workspace = true, features = ["derive"] }
16+
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] }
17+
futures = { workspace = true }
18+
zip = { workspace = true }
19+
bytes = { workspace = true }

cli/src/command/definition.rs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
use code0_definition_reader::parser::Parser;
2+
use colored::Colorize;
3+
4+
pub fn search_definition(name: String, path: Option<String>) {
5+
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
6+
7+
let parser = match Parser::from_path(dir_path.as_str()) {
8+
Some(reader) => reader,
9+
None => {
10+
panic!("Error reading definitions");
11+
}
12+
};
13+
14+
search_and_display_definitions(&name, &parser);
15+
}
16+
17+
fn search_and_display_definitions(search_name: &str, parser: &Parser) {
18+
let mut found_any = false;
19+
let mut total_matches = 0;
20+
println!(
21+
"{}",
22+
format!("Searching for definitions matching: '{search_name}'")
23+
.bright_yellow()
24+
.bold()
25+
);
26+
println!("{}", "─".repeat(60).dimmed());
27+
28+
for feature in &parser.features {
29+
// Search FlowTypes
30+
for flow_type in &feature.flow_types {
31+
if flow_type.identifier == search_name {
32+
total_matches += 1;
33+
if !found_any {
34+
found_any = true;
35+
}
36+
37+
println!("\n{}", "FlowType".bright_cyan().bold());
38+
match serde_json::to_string_pretty(flow_type) {
39+
Ok(json) => {
40+
let mut index = 0;
41+
for line in json.lines() {
42+
index += 1;
43+
println!(
44+
"{} {}",
45+
format!("{index}:").bright_blue(),
46+
line.bright_green()
47+
);
48+
}
49+
}
50+
Err(_) => println!("{}", "Error serializing FlowType".red()),
51+
}
52+
}
53+
}
54+
55+
// Search DataTypes
56+
for data_type in &feature.data_types {
57+
if data_type.identifier == search_name {
58+
total_matches += 1;
59+
if !found_any {
60+
found_any = true;
61+
}
62+
63+
println!("\n{}", "DataType".bright_cyan().bold());
64+
match serde_json::to_string_pretty(data_type) {
65+
Ok(json) => {
66+
let mut index = 0;
67+
for line in json.lines() {
68+
index += 1;
69+
println!(
70+
"{} {}",
71+
format!("{index}:").bright_blue(),
72+
line.bright_green()
73+
);
74+
}
75+
}
76+
Err(_) => println!("{}", "Error serializing DataType".red()),
77+
}
78+
}
79+
}
80+
81+
// Search RuntimeFunctions
82+
for runtime_func in &feature.runtime_functions {
83+
if runtime_func.runtime_name == search_name {
84+
total_matches += 1;
85+
if !found_any {
86+
found_any = true;
87+
}
88+
89+
println!("\n{}", "RuntimeFunction".bright_cyan().bold());
90+
match serde_json::to_string_pretty(runtime_func) {
91+
Ok(json) => {
92+
let mut index = 0;
93+
for line in json.lines() {
94+
index += 1;
95+
println!(
96+
"{} {}",
97+
format!("{index}:").bright_blue(),
98+
line.bright_green()
99+
);
100+
}
101+
}
102+
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
103+
}
104+
}
105+
}
106+
}
107+
108+
if !found_any {
109+
println!(
110+
"\n{}",
111+
format!("No definitions found matching '{search_name}'")
112+
.red()
113+
.bold()
114+
);
115+
} else {
116+
println!("\n{}", "─".repeat(60).dimmed());
117+
println!(
118+
"{}",
119+
format!("Found {total_matches} matching definition(s)").bright_yellow()
120+
);
121+
}
122+
}

0 commit comments

Comments
 (0)