-
Notifications
You must be signed in to change notification settings - Fork 52
New Templates & Changes in CLI #790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
aa0b7d3
6efc6c9
a03fee0
77eccbb
629695a
eb8eb09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,8 +28,22 @@ pub mod evm { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Clone, Debug, ValueEnum, Serialize, Deserialize, EnumIter, EnumString, Display)] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pub enum Template { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Greeter")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Greeter, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "ERC20")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Erc20, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: Topic Filtering")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TopicFiltering, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: Wildcard Indexing")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| WildcardIndexing, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: onBlock Handler")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| OnBlockHandler, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainTemplate naming/serialization may drift across clap/strum/serde. Verify UX strings and parsing.
Please confirm:
You can run: 🏁 Script executed: #!/bin/bash
# Inspect enum variants and any template mappings
rg -nP 'enum\s+Template\b' -C2 codegenerator/cli
rg -nP 'supported_languages\s*\(' codegenerator/cli
rg -nP '(effects_api_template|factory_indexer_template|multichain_indexer_template)' -n codegenerator/cliLength of output: 1647 I need to gather more information about the Template enums and how they're used.<!-- [scratchpad_update]
[pending_critical]
Need to inspect the actual Template enum and template registration in more detail. 🏁 Script executed: #!/bin/bash
# Get full context of the Template enum at line 30
sed -n '28,80p' codegenerator/cli/src/cli_args/init_config.rsLength of output: 2220 🏁 Script executed: #!/bin/bash
# Get full context of the second Template enum at line 231
sed -n '229,240p' codegenerator/cli/src/cli_args/init_config.rsLength of output: 285 🏁 Script executed: #!/bin/bash
# Look for clap attributes on Template enum
rg -nP '#\[clap' codegenerator/cli/src/cli_args/init_config.rs -A2 -B2Length of output: 243 🏁 Script executed: #!/bin/bash
# Search for new template names in template_dirs.rs
rg -nP '(effects|factory|multichain)' codegenerator/cli/src/template_dirs.rs -i -C2Length of output: 0 🏁 Script executed: #!/bin/bash
# Check if there's a match on Template enum and ValueEnum derive to understand how it's used
ast-grep --pattern $'#[derive($$$ValueEnum$$$)]
pub enum Template {
$$$
}'Length of output: 0 🏁 Script executed: #!/bin/bash
# Look for clap rename_all on the enum itself
rg -nP 'enum Template' codegenerator/cli -B5 | head -40Length of output: 1303 🏁 Script executed: #!/bin/bash
# Search in template_dirs for TemplateProvider or template registration logic
rg -nP 'fn.*template' codegenerator/cli/src/template_dirs.rs -i -nLength of output: 1251 🏁 Script executed: #!/bin/bash
# Look for where Template enum variants are used in value parsing
rg -nP 'to_possible_value|value_variants|Template::' codegenerator/cli/src/cli_args/init_config.rs -nLength of output: 0 🏁 Script executed: #!/bin/bash
# Check if there's any test or mock for template selection
fd -e rs codegenerator/cli -path '*/test*' -o -name '*test*' | xargs rg -l Template 2>/dev/null | head -5Length of output: 360 🏁 Script executed: #!/bin/bash
# Look for explicit use of strum in imports or dependencies
rg -n '^use.*strum' codegenerator/cli/src/Length of output: 991 🏁 Script executed: #!/bin/bash
# Look for where Template is actually parsed/matched in the interactive flow
rg -nP 'Template::|template.*select|select.*template' codegenerator/cli/src/cli_args/interactive_init/ -iLength of output: 932 🏁 Script executed: #!/bin/bash
# Check Cargo.toml for versions of clap, strum, serde
rg -n '(clap|strum|serde)' codegenerator/cli/Cargo.toml -A1Length of output: 379 🏁 Script executed: #!/bin/bash
# Look at the full enum definition including derive macros
sed -n '25,100p' codegenerator/cli/src/cli_args/init_config.rsLength of output: 3034 I need to verify a few more critical details about how Template enum is used in argument parsing and whether clap attributes exist at the module level. 🏁 Script executed: #!/bin/bash
# Check if Template is used in clap argument definitions
rg -nP 'template|Template' codegenerator/cli/src/cli_args/clap_definitions.rs -i -C3Length of output: 1763 🏁 Script executed: #!/bin/bash
# Look at the evm module declaration to see if there are clap attributes
sed -n '1,50p' codegenerator/cli/src/cli_args/init_config.rsLength of output: 1537 🏁 Script executed: #!/bin/bash
# Check how the Template is rendered in the interactive prompt (Display impl check)
rg -nP 'shared_prompts|SelectItem' codegenerator/cli/src/cli_args/interactive_init/shared_prompts.rs -C5Length of output: 887 🏁 Script executed: #!/bin/bash
# Look for where template names are actually output to user (help text, prompts)
rg -nP 'which.*template|select.*template' codegenerator/cli/src/cli_args/interactive_init/ -i -C3Length of output: 1539 🏁 Script executed: #!/bin/bash
# Check TemplateType enum to understand template registration
sed -n '179,220p' codegenerator/cli/src/template_dirs.rsLength of output: 1422 🏁 Script executed: #!/bin/bash
# Look for any rename_all or clap rename directives on evm module
grep -n 'mod evm' codegenerator/cli/src/cli_args/init_config.rs -B5 -A10Length of output: 411 🏁 Script executed: #!/bin/bash
# Search for ValueEnum implementation to see if to_possible_value is customized
rg -nP 'impl.*ValueEnum|to_possible_value' codegenerator/cli/src/cli_args/init_config.rs -nLength of output: 0 🏁 Script executed: #!/bin/bash
# Check template_dirs.rs TemplateType for variant names
sed -n '179,200p' codegenerator/cli/src/template_dirs.rsLength of output: 679 Add The review concern is valid. Template enum (line 29-40) derives ValueEnum without explicit clap attributes, causing a mismatch:
This breaks non-interactive flag parsing (e.g., Fix: Add Regarding new templates: effects_api_template, factory_indexer_template, multichain_indexer_template are not found in the Template enum or template_dirs.rs. Verify whether these should be added to the enum or are intentionally excluded. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: Effects API")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| EffectsAPI, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: Factory Indexer")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| FactoryIndexer, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[strum(serialize = "Feature: Multichain Indexer")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| MultichainIndexer, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ///A an object that holds all the values a user can select during | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -335,21 +349,15 @@ impl Ecosystem { | |||||||||||||||||||||||||||||||||||||||||||||||||
| )] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ///Which language do you want to write in? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pub enum Language { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[clap(name = "javascript")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| JavaScript, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[clap(name = "typescript")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TypeScript, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #[clap(name = "rescript")] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ReScript, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| impl Language { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Logic to get the event handler directory based on the language | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn get_event_handler_directory(&self) -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Language::ReScript => "./src/EventHandlers.res.js".to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Language::TypeScript => "src/EventHandlers.ts".to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Language::JavaScript => "./src/EventHandlers.js".to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,6 @@ use crate::{ | |||||||||||
| use anyhow::{Context, Result}; | ||||||||||||
| use inquire::{Select, Text}; | ||||||||||||
| use shared_prompts::prompt_template; | ||||||||||||
| use std::str::FromStr; | ||||||||||||
| use strum; | ||||||||||||
| use strum::{Display, EnumIter, IntoEnumIterator}; | ||||||||||||
| use validation::{ | ||||||||||||
|
|
@@ -30,7 +29,9 @@ enum EcosystemOption { | |||||||||||
| Fuel, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| async fn prompt_ecosystem(cli_init_flow: Option<InitFlow>) -> Result<Ecosystem> { | ||||||||||||
| async fn prompt_ecosystem( | ||||||||||||
| cli_init_flow: Option<InitFlow>, | ||||||||||||
| ) -> Result<Ecosystem> { | ||||||||||||
| let init_flow = match cli_init_flow { | ||||||||||||
| Some(v) => v, | ||||||||||||
| None => { | ||||||||||||
|
|
@@ -138,22 +139,7 @@ pub async fn prompt_missing_init_args( | |||||||||||
| } | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| let language = match init_args.language { | ||||||||||||
| Some(args_language) => args_language, | ||||||||||||
| None => { | ||||||||||||
| let options = Language::iter() | ||||||||||||
| .map(|language| language.to_string()) | ||||||||||||
| .collect::<Vec<String>>(); | ||||||||||||
|
|
||||||||||||
| let input_language = Select::new("Which language would you like to use?", options) | ||||||||||||
| .with_starting_cursor(1) | ||||||||||||
| .prompt() | ||||||||||||
| .context("prompting user to select language")?; | ||||||||||||
|
|
||||||||||||
| Language::from_str(&input_language) | ||||||||||||
| .context("parsing user input for language selection")? | ||||||||||||
| } | ||||||||||||
| }; | ||||||||||||
| let language = Language::TypeScript; | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd do it this way. Also need to perform this check only for contract import flow. Since templates are TS only.
Suggested change
|
||||||||||||
|
|
||||||||||||
| let ecosystem = prompt_ecosystem(init_args.init_commands) | ||||||||||||
| .await | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,8 +253,7 @@ impl Event { | |
| /// Returns the code to get the entity id from an event | ||
| pub fn get_entity_id_code(is_fuel: bool, language: &Language) -> String { | ||
| let int_as_string = |int_var_name| match language { | ||
| Language::ReScript => format!("{int_var_name}->Belt.Int.toString"), | ||
| Language::TypeScript | Language::JavaScript => int_var_name, | ||
| Language::TypeScript => int_var_name, | ||
|
Comment on lines
255
to
+256
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep ReScript here |
||
| }; | ||
| let int_event_prop_as_string = | ||
| |event_prop: &str| int_as_string(format!("event.{event_prop}")); | ||
|
|
@@ -281,9 +280,7 @@ impl Event { | |
| match is_fuel { | ||
| true => { | ||
| let data_code = match language { | ||
| Language::ReScript => "%raw(`{}`)", | ||
| Language::TypeScript => "{}", | ||
| Language::JavaScript => "{}", | ||
| }; | ||
| format!( | ||
| "{event_module}.mock({{data: {data_code} /* It mocks event fields with \ | ||
|
|
@@ -566,12 +563,6 @@ mod test { | |
| #[test] | ||
| fn test_get_entity_id_code() { | ||
| const IS_FUEL: bool = true; | ||
| assert_eq!( | ||
| Event::get_entity_id_code(!IS_FUEL, &Language::ReScript), | ||
| "`${event.chainId->Belt.Int.toString}_${event.block.number->Belt.Int.\ | ||
| toString}_${event.logIndex->Belt.Int.toString}`" | ||
| .to_string() | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| Event::get_entity_id_code(IS_FUEL, &Language::TypeScript), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to keep ReScript option for contract import. No need to have a promt for it, only as a cli.