Skip to content

Commit f61aebb

Browse files
authored
Add a command to Graphene CLI for listing protonode identifiers (#3399)
* Add proto node name printing * Add subcommand for printing proto node identifiers * Address review comments * Cargo fmt
1 parent 06484ef commit f61aebb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

node-graph/graphene-cli/src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graph_craft::proto::ProtoNetwork;
77
use graph_craft::util::load_network;
88
use graph_craft::wasm_application_io::EditorPreferences;
99
use graphene_std::application_io::{ApplicationIo, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
10-
use graphene_std::text_nodes::FontCache;
10+
use graphene_std::text::FontCache;
1111
use graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi};
1212
use interpreted_executor::dynamic_executor::DynamicExecutor;
1313
use interpreted_executor::util::wrap_network_in_scope;
@@ -56,6 +56,7 @@ enum Command {
5656
#[clap(long, short = 'l')]
5757
run_loop: bool,
5858
},
59+
ListNodeIdentifiers,
5960
}
6061

6162
#[derive(Debug, Args)]
@@ -76,12 +77,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
7677
let document_path = match app.command {
7778
Command::Compile { ref document, .. } => document,
7879
Command::Run { ref document, .. } => document,
80+
Command::ListNodeIdentifiers => {
81+
let mut ids: Vec<_> = graphene_std::registry::NODE_METADATA.lock().unwrap().keys().cloned().collect();
82+
ids.sort_by_key(|x| x.name.clone());
83+
for id in ids {
84+
println!("{}", id.name)
85+
}
86+
return Ok(());
87+
}
7988
};
8089

8190
let document_string = std::fs::read_to_string(document_path).expect("Failed to read document");
8291

8392
log::info!("creating gpu context",);
84-
let mut application_io = block_on(WasmApplicationIo::new());
93+
let mut application_io = block_on(WasmApplicationIo::new_offscreen());
8594

8695
if let Command::Run { image: Some(ref image_path), .. } = app.command {
8796
application_io.resources.insert("null".to_string(), Arc::from(std::fs::read(image_path).expect("Failed to read image")));
@@ -123,6 +132,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
123132
tokio::time::sleep(std::time::Duration::from_millis(16)).await;
124133
}
125134
}
135+
_ => unreachable!("All other commands should be handled before this match statement is run"),
126136
}
127137

128138
Ok(())
@@ -168,7 +178,8 @@ fn fix_nodes(network: &mut NodeNetwork) {
168178
// https://github.com/GraphiteEditor/Graphite/blob/d68f91ccca69e90e6d2df78d544d36cd1aaf348e/editor/src/messages/portfolio/portfolio_message_handler.rs#L535
169179
// Since the CLI doesn't have the document node definitions, a less robust method of just patching the inputs is used.
170180
DocumentNodeImplementation::ProtoNode(proto_node_identifier)
171-
if (proto_node_identifier.name.starts_with("core_types::ConstructLayerNode") || proto_node_identifier.name.starts_with("core_types::AddArtboardNode")) && node.inputs.len() < 3 =>
181+
if (proto_node_identifier.name.starts_with("graphene_core::ConstructLayerNode") || proto_node_identifier.name.starts_with("graphene_core::AddArtboardNode"))
182+
&& node.inputs.len() < 3 =>
172183
{
173184
node.inputs.push(NodeInput::Reflection(DocumentNodeMetadata::DocumentNodePath));
174185
}

0 commit comments

Comments
 (0)