Skip to content

Commit f7b6418

Browse files
committed
feat(forge): deprecate generate
This command is very simplistic and does not achieve much other than a simple template replacement. This can easily be implemented in your editor or extension of choice as a macro, fitting your stylistic needs.
1 parent f7563cf commit f7b6418

File tree

3 files changed

+7
-63
lines changed

3 files changed

+7
-63
lines changed

crates/forge/src/args.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch},
2+
cmd::{cache::CacheSubcommands, watch},
33
opts::{Forge, ForgeSubcommand},
44
};
55
use clap::{CommandFactory, Parser};
@@ -137,9 +137,7 @@ pub fn run_command(args: Forge) -> Result<()> {
137137
}
138138
}
139139
ForgeSubcommand::Selectors { command } => global.block_on(command.run()),
140-
ForgeSubcommand::Generate(cmd) => match cmd.sub {
141-
GenerateSubcommands::Test(cmd) => cmd.run(),
142-
},
140+
ForgeSubcommand::Generate(cmd) => cmd.run(),
143141
ForgeSubcommand::Compiler(cmd) => cmd.run(),
144142
ForgeSubcommand::Soldeer(cmd) => global.block_on(cmd.run()),
145143
ForgeSubcommand::Eip712(cmd) => cmd.run(),
Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,15 @@
1-
use clap::{Parser, Subcommand};
1+
use clap::Parser;
22
use eyre::Result;
3-
use foundry_common::fs;
4-
use std::path::Path;
5-
use yansi::Paint;
63

74
/// CLI arguments for `forge generate`.
85
#[derive(Debug, Parser)]
96
pub struct GenerateArgs {
10-
#[command(subcommand)]
11-
pub sub: GenerateSubcommands,
7+
args: Vec<String>,
128
}
139

14-
#[derive(Debug, Subcommand)]
15-
pub enum GenerateSubcommands {
16-
/// Scaffolds test file for given contract.
17-
Test(GenerateTestArgs),
18-
}
19-
20-
#[derive(Debug, Parser)]
21-
pub struct GenerateTestArgs {
22-
/// Contract name for test generation.
23-
#[arg(long, short, value_name = "CONTRACT_NAME")]
24-
pub contract_name: String,
25-
}
26-
27-
impl GenerateTestArgs {
10+
impl GenerateArgs {
2811
pub fn run(self) -> Result<()> {
29-
let contract_name = format_identifier(&self.contract_name, true);
30-
let instance_name = format_identifier(&self.contract_name, false);
31-
32-
// Create the test file content.
33-
let test_content = include_str!("../../../assets/generated/TestTemplate.t.sol");
34-
let test_content = test_content
35-
.replace("{contract_name}", &contract_name)
36-
.replace("{instance_name}", &instance_name);
37-
38-
// Create the test directory if it doesn't exist.
39-
fs::create_dir_all("test")?;
40-
41-
// Define the test file path
42-
let test_file_path = Path::new("test").join(format!("{contract_name}.t.sol"));
43-
44-
// Write the test content to the test file.
45-
fs::write(&test_file_path, test_content)?;
46-
47-
sh_println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap())?;
12+
sh_warn!("`forge generate` is deprecated and will be removed in a future version")?;
4813
Ok(())
4914
}
5015
}
51-
52-
/// Utility function to convert an identifier to pascal or camel case.
53-
fn format_identifier(input: &str, is_pascal_case: bool) -> String {
54-
let mut result = String::new();
55-
let mut capitalize_next = is_pascal_case;
56-
57-
for word in input.split_whitespace() {
58-
if !word.is_empty() {
59-
let (first, rest) = word.split_at(1);
60-
let formatted_word = if capitalize_next {
61-
format!("{}{}", first.to_uppercase(), rest)
62-
} else {
63-
format!("{}{}", first.to_lowercase(), rest)
64-
};
65-
capitalize_next = true;
66-
result.push_str(&formatted_word);
67-
}
68-
}
69-
result
70-
}

crates/forge/src/opts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub enum ForgeSubcommand {
160160
},
161161

162162
/// Generate scaffold files.
163+
#[command(hide = true)]
163164
Generate(generate::GenerateArgs),
164165

165166
/// Compiler utilities.

0 commit comments

Comments
 (0)