Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,333 changes: 1,291 additions & 42 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ edition = "2024"
serde = "1.0.219"
serde_json = "1.0.140"
tucana = "0.0.32"
clap = { version = "4.5.41" }
clap = "4.5.41"
colored = "2.0"
tabled = "0.15"
notify = "6.0"
reqwest = "0.12.22"
tokio = "1.47.0"
futures = "0.3.31"
zip = "4.3.0"
bytes = "1.10.1"

[workspace.dependencies.code0-definition-reader]
path = "../code0-definition/reader/rust"
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Definitions
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.

## Definition CLI

Expand All @@ -7,27 +8,46 @@

### Usage
(Stay inside the root directory when running the command)
### General Report

#### Download
Will download the latest Definitions from the Code0 Definition Repository.

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.

```bash
./cargo run download
./cargo run download -f feature_1 feature_2 feature_3
```

#### General Report
Will create a report of all errors in the definitions.

```bash
./cargo run report
./cargo run report -p /path/to/definitions
```

### Feature Report
#### Feature Report
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.

```bash
./cargo run feature
./cargo run feature -p /path/to/definitions
./cargo run feature -f feature_name
./cargo run feature -f feature_name -p /path/to/definitions
```

### Watch for Changes
#### Watch for Changes
Will run the report each time a definition file changes.

```bash
./cargo run watch
./cargo run watch -p /path/to/definitions
```

### Definition
#### Definition
Will search for a specific definition.

```bash
./cargo run definition -n definition_name
./cargo run definition -n definition_name -p /path/to/definitions
Expand All @@ -53,3 +73,24 @@ for (const feature in features) {
}
```

## Rust Definition Package

### Install Package
```bash
cargo add code0-definition-reader
```

### Usage

```rs
use code0_definition_reader::Definition;

let features = Definition::new("./path/to/definitions");

for feature in features {
let name = feature.name(); //name of the feature (e.g. rest)
let data_types = feature.data_types(); //dataTypes of this feature
let flow_types = feature.flow_types(); //flowTypes of this feature
let functions = feature.runtime_functions(); //runtimeFunctions of this feature
}
```
6 changes: 6 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ colored = { workspace = true }
tabled = { workspace = true }
notify = { workspace = true }
serde_json = { workspace = true }
reqwest = { workspace = true, features = ["json", "stream"] }
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] }
futures = { workspace = true }
zip = { workspace = true }
bytes = { workspace = true }
122 changes: 122 additions & 0 deletions cli/src/command/definition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use code0_definition_reader::parser::Parser;
use colored::Colorize;

pub fn search_definition(name: String, path: Option<String>) {
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());

let parser = match Parser::from_path(dir_path.as_str()) {
Some(reader) => reader,
None => {
panic!("Error reading definitions");
}
};

search_and_display_definitions(&name, &parser);
}

fn search_and_display_definitions(search_name: &str, parser: &Parser) {
let mut found_any = false;
let mut total_matches = 0;
println!(
"{}",
format!("Searching for definitions matching: '{search_name}'")
.bright_yellow()
.bold()
);
println!("{}", "─".repeat(60).dimmed());

for feature in &parser.features {
// Search FlowTypes
for flow_type in &feature.flow_types {
if flow_type.identifier == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}

println!("\n{}", "FlowType".bright_cyan().bold());
match serde_json::to_string_pretty(flow_type) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing FlowType".red()),
}
}
}

// Search DataTypes
for data_type in &feature.data_types {
if data_type.identifier == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}

println!("\n{}", "DataType".bright_cyan().bold());
match serde_json::to_string_pretty(data_type) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing DataType".red()),
}
}
}

// Search RuntimeFunctions
for runtime_func in &feature.runtime_functions {
if runtime_func.runtime_name == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}

println!("\n{}", "RuntimeFunction".bright_cyan().bold());
match serde_json::to_string_pretty(runtime_func) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
}
}
}
}

if !found_any {
println!(
"\n{}",
format!("No definitions found matching '{search_name}'")
.red()
.bold()
);
} else {
println!("\n{}", "─".repeat(60).dimmed());
println!(
"{}",
format!("Found {total_matches} matching definition(s)").bright_yellow()
);
}
}
Loading