Skip to content

Commit 4400029

Browse files
committed
Generate docs
1 parent 2327a36 commit 4400029

File tree

5 files changed

+191
-68
lines changed

5 files changed

+191
-68
lines changed

src/config/dot_graph.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@ pub struct GraphConfig {
2424
///
2525
/// They are added to the edge as provided
2626
#[configurable(metadata(
27-
docs::additional_props_description = "A single graph edge attribute in graphviz DOT language.",
28-
docs::examples = "example_edge_options()"
27+
docs::additional_props_description = "A collection of graph edge attributes in graphviz DOT language, related to a single input component.",
28+
docs::examples = "example_edges_options()"
2929
))]
3030
#[serde(default)]
31-
pub edge_attributes: HashMap<String, HashMap<String, String>>,
31+
pub edge_attributes: HashMap<String, EdgeAttributes>,
3232
}
3333

34+
#[configurable_component]
35+
#[configurable(metadata(docs::advanced))]
36+
#[derive(Clone, Debug, Default, Eq, PartialEq)]
37+
#[serde(deny_unknown_fields)]
38+
/// A collection of graph edge attributes in graphviz DOT language, related to a single input
39+
/// component.
40+
pub struct EdgeAttributes(
41+
#[configurable(metadata(
42+
docs::additional_props_description = "A single graph edge attribute in graphviz DOT language.",
43+
docs::examples = "example_edge_options()"
44+
))]
45+
pub HashMap<String, String>,
46+
);
47+
3448
fn example_node_options() -> HashMap<String, String> {
3549
HashMap::<_, _>::from_iter([
3650
("name".to_string(), "Example Node".to_string()),
@@ -39,13 +53,14 @@ fn example_node_options() -> HashMap<String, String> {
3953
])
4054
}
4155

42-
fn example_edge_options() -> HashMap<String, HashMap<String, String>> {
43-
HashMap::<_, _>::from_iter([(
44-
"example_input".to_string(),
45-
HashMap::<_, _>::from_iter([
46-
("label".to_string(), "Example Edge".to_string()),
47-
("color".to_string(), "red".to_string()),
48-
("width".to_string(), "5.0".to_string()),
49-
]),
50-
)])
56+
fn example_edges_options() -> HashMap<String, HashMap<String, String>> {
57+
HashMap::<_, _>::from_iter([("example_input".to_string(), example_edge_options())])
58+
}
59+
60+
fn example_edge_options() -> HashMap<String, String> {
61+
HashMap::<_, _>::from_iter([
62+
("label".to_string(), "Example Edge".to_string()),
63+
("color".to_string(), "red".to_string()),
64+
("width".to_string(), "5.0".to_string()),
65+
])
5166
}

src/graph.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use clap::Parser;
88
use itertools::Itertools;
99
use vector_lib::{config::OutputId, id::ComponentKey};
1010

11-
use crate::config::{self, dot_graph::GraphConfig};
11+
use crate::config::{
12+
self,
13+
dot_graph::{EdgeAttributes, GraphConfig},
14+
};
1215

1316
#[derive(Parser, Debug)]
1417
#[command(rename_all = "kebab-case")]
@@ -99,11 +102,8 @@ fn node_attributes_to_string(attributes: &HashMap<String, String>, default_shape
99102
attrs.iter().map(|(k, v)| format!("{k}=\"{v}\"")).join(" ")
100103
}
101104

102-
fn edge_attributes_to_string(
103-
attributes: &HashMap<String, String>,
104-
default_label: Option<&str>,
105-
) -> String {
106-
let mut attrs = attributes.clone();
105+
fn edge_attributes_to_string(attributes: &EdgeAttributes, default_label: Option<&str>) -> String {
106+
let mut attrs = attributes.0.clone();
107107
if let Some(default_label) = default_label
108108
&& !attrs.contains_key("label")
109109
{
@@ -233,7 +233,10 @@ fn render_dot_edge(into: &mut String, id: &ComponentKey, input: &OutputId, graph
233233
" \"{}\" -> \"{}\" [{}]",
234234
input.component,
235235
id,
236-
edge_attributes_to_string(edge_attributes.unwrap_or(&HashMap::default()), Some(port))
236+
edge_attributes_to_string(
237+
edge_attributes.unwrap_or(&EdgeAttributes::default()),
238+
Some(port)
239+
)
237240
)
238241
.expect("write to String never fails");
239242
} else if let Some(edge_attributes) = edge_attributes {

website/cue/reference/components/generated/sinks.cue

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,58 @@ generated: components: sinks: configuration: {
8282
Configure output for component when generated with graph command
8383
"""
8484
required: false
85-
type: object: options: node_attributes: {
86-
description: """
87-
Node attributes to add to this component's node in resulting graph
88-
89-
They are added to the node as provided
90-
"""
91-
required: false
92-
type: object: {
93-
examples: [{
94-
color: "red"
95-
name: "Example Node"
96-
width: "5.0"
97-
}]
98-
options: "*": {
99-
description: "A single graph node attribute in graphviz DOT language."
100-
required: true
101-
type: string: {}
85+
type: object: options: {
86+
edge_attributes: {
87+
description: """
88+
Edge attributes to add to the edges linked to this component's node in resulting graph
89+
90+
They are added to the edge as provided
91+
"""
92+
required: false
93+
type: object: {
94+
examples: [{
95+
example_input: {
96+
color: "red"
97+
label: "Example Edge"
98+
width: "5.0"
99+
}
100+
}]
101+
options: "*": {
102+
description: "A collection of graph edge attributes in graphviz DOT language, related to a single input component."
103+
required: true
104+
type: object: {
105+
examples: [{
106+
color: "red"
107+
label: "Example Edge"
108+
width: "5.0"
109+
}]
110+
options: "*": {
111+
description: "A single graph edge attribute in graphviz DOT language."
112+
required: true
113+
type: string: {}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
node_attributes: {
120+
description: """
121+
Node attributes to add to this component's node in resulting graph
122+
123+
They are added to the node as provided
124+
"""
125+
required: false
126+
type: object: {
127+
examples: [{
128+
color: "red"
129+
name: "Example Node"
130+
width: "5.0"
131+
}]
132+
options: "*": {
133+
description: "A single graph node attribute in graphviz DOT language."
134+
required: true
135+
type: string: {}
136+
}
102137
}
103138
}
104139
}

website/cue/reference/components/generated/sources.cue

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,58 @@ generated: components: sources: configuration: {
88
Configure output for component when generated with graph command
99
"""
1010
required: false
11-
type: object: options: node_attributes: {
12-
description: """
13-
Node attributes to add to this component's node in resulting graph
11+
type: object: options: {
12+
edge_attributes: {
13+
description: """
14+
Edge attributes to add to the edges linked to this component's node in resulting graph
15+
16+
They are added to the edge as provided
17+
"""
18+
required: false
19+
type: object: {
20+
examples: [{
21+
example_input: {
22+
color: "red"
23+
label: "Example Edge"
24+
width: "5.0"
25+
}
26+
}]
27+
options: "*": {
28+
description: "A collection of graph edge attributes in graphviz DOT language, related to a single input component."
29+
required: true
30+
type: object: {
31+
examples: [{
32+
color: "red"
33+
label: "Example Edge"
34+
width: "5.0"
35+
}]
36+
options: "*": {
37+
description: "A single graph edge attribute in graphviz DOT language."
38+
required: true
39+
type: string: {}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
node_attributes: {
46+
description: """
47+
Node attributes to add to this component's node in resulting graph
1448
15-
They are added to the node as provided
16-
"""
17-
required: false
18-
type: object: {
19-
examples: [{
20-
color: "red"
21-
name: "Example Node"
22-
width: "5.0"
23-
}]
24-
options: "*": {
25-
description: "A single graph node attribute in graphviz DOT language."
26-
required: true
27-
type: string: {}
49+
They are added to the node as provided
50+
"""
51+
required: false
52+
type: object: {
53+
examples: [{
54+
color: "red"
55+
name: "Example Node"
56+
width: "5.0"
57+
}]
58+
options: "*": {
59+
description: "A single graph node attribute in graphviz DOT language."
60+
required: true
61+
type: string: {}
62+
}
2863
}
2964
}
3065
}

website/cue/reference/components/generated/transforms.cue

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,58 @@ generated: components: transforms: configuration: {
88
Configure output for component when generated with graph command
99
"""
1010
required: false
11-
type: object: options: node_attributes: {
12-
description: """
13-
Node attributes to add to this component's node in resulting graph
11+
type: object: options: {
12+
edge_attributes: {
13+
description: """
14+
Edge attributes to add to the edges linked to this component's node in resulting graph
1415
15-
They are added to the node as provided
16-
"""
17-
required: false
18-
type: object: {
19-
examples: [{
20-
color: "red"
21-
name: "Example Node"
22-
width: "5.0"
23-
}]
24-
options: "*": {
25-
description: "A single graph node attribute in graphviz DOT language."
26-
required: true
27-
type: string: {}
16+
They are added to the edge as provided
17+
"""
18+
required: false
19+
type: object: {
20+
examples: [{
21+
example_input: {
22+
color: "red"
23+
label: "Example Edge"
24+
width: "5.0"
25+
}
26+
}]
27+
options: "*": {
28+
description: "A collection of graph edge attributes in graphviz DOT language, related to a single input component."
29+
required: true
30+
type: object: {
31+
examples: [{
32+
color: "red"
33+
label: "Example Edge"
34+
width: "5.0"
35+
}]
36+
options: "*": {
37+
description: "A single graph edge attribute in graphviz DOT language."
38+
required: true
39+
type: string: {}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
node_attributes: {
46+
description: """
47+
Node attributes to add to this component's node in resulting graph
48+
49+
They are added to the node as provided
50+
"""
51+
required: false
52+
type: object: {
53+
examples: [{
54+
color: "red"
55+
name: "Example Node"
56+
width: "5.0"
57+
}]
58+
options: "*": {
59+
description: "A single graph node attribute in graphviz DOT language."
60+
required: true
61+
type: string: {}
62+
}
2863
}
2964
}
3065
}

0 commit comments

Comments
 (0)