Skip to content

Commit 38e9bab

Browse files
committed
fix output dir
1 parent 813dbc4 commit 38e9bab

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

app/src/main/java/io/ballerina/web3/cli/Cli.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package io.ballerina.web3.cli;
2020

21+
import io.ballerina.cli.BLauncherCmd;
2122
import io.ballerina.web3.abi.AbiEntry;
2223
import io.ballerina.web3.abi.AbiReader;
2324
import io.ballerina.web3.generator.Generator;
@@ -28,18 +29,27 @@
2829
import java.nio.file.Path;
2930
import java.util.List;
3031

31-
@Command(name = "web3-cli", mixinStandardHelpOptions = true, version = "1.0", description = "Generates Ballerina connectors from Ethereum Smart Contract ABI.")
32-
public class Cli implements Runnable {
32+
@Command(name = "web3", description = "Generates Ballerina connectors from Ethereum Smart Contract ABI.")
33+
public class Cli implements BLauncherCmd {
34+
35+
private static final String CMD_NAME = "web3";
3336

3437
@Option(names = { "-a", "--abi" }, required = true, description = "Path to the ABI JSON file")
3538
private String abiPath;
3639

3740
@Option(names = { "-o", "--output" }, description = "Output directory")
3841
private String outputDir = "./generated/";
3942

43+
@Option(names = { "-h", "--help" }, usageHelp = true, description = "Display help information")
44+
private boolean helpFlag;
45+
4046
@Override
41-
public void run() {
42-
// Validate ABI file before processing
47+
public void execute() {
48+
if (helpFlag) {
49+
printUsage(new StringBuilder());
50+
return;
51+
}
52+
4353
if (!isFileValid(abiPath)) {
4454
System.err.println("Error: ABI file does not exist or is not a valid file: " + abiPath);
4555
return;
@@ -56,17 +66,34 @@ public void run() {
5666
}
5767

5868
private void generateBallerinaConnector() throws Exception {
59-
System.out.println("Generating Ballerina connector...");
60-
6169
AbiReader abiReader = new AbiReader(abiPath);
62-
6370
List<AbiEntry> abiEntries = abiReader.read();
64-
65-
Generator.generate(abiEntries);
71+
Generator.generate(abiEntries, outputDir);
6672
}
6773

6874
private boolean isFileValid(String filePath) {
6975
Path path = Path.of(filePath);
7076
return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path);
7177
}
78+
79+
@Override
80+
public String getName() {
81+
return CMD_NAME;
82+
}
83+
84+
@Override
85+
public void printLongDesc(StringBuilder out) {
86+
out.append("Generates Ballerina connectors from Ethereum Smart Contract ABI.\n")
87+
.append("This tool takes an ABI JSON file and generates a Ballerina connector.\n");
88+
}
89+
90+
@Override
91+
public void printUsage(StringBuilder out) {
92+
out.append("bal web3 -a <path/to/abi.json> [-o <output-dir>]\n");
93+
}
94+
95+
@Override
96+
public void setParentCmdParser(picocli.CommandLine parentCmdParser) {
97+
// Not needed for now
98+
}
7299
}

app/src/main/java/io/ballerina/web3/generator/Generator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import io.ballerina.web3.generator.utils.FileUtils;
2626

2727
public class Generator {
28-
public static void generate(List<AbiEntry> abiEntries) throws FormatterException {
28+
public static void generate(List<AbiEntry> abiEntries, String outputDir) throws FormatterException {
2929
String sourceCode = ClientGenerator.generate(abiEntries);
3030

31-
FileUtils.writeToFile("src/output/main.bal", sourceCode);
32-
FileUtils.copyResourceToOutput("utils.bal", "src/output");
31+
FileUtils.writeToFile(outputDir + "/main.bal", sourceCode);
32+
FileUtils.copyResourceToOutput("utils.bal", outputDir);
3333
}
3434
}

0 commit comments

Comments
 (0)