Skip to content

Commit

Permalink
add smithy dir as arg
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Sep 17, 2024
1 parent 791b1ab commit 0b497bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ public class CliOptions {
.desc("Service Name to be generated as String")
.build();

private static final Option SmithyModelPathOption = Option.builder()
.option("sm")
.longOpt("smithyModels")
.hasArg(true)
.required(true)
.desc("Path to smithy models")
.build();

public static CliOptions BuildFromInput(String[] args) throws ParseException {
final Options options = new Options();
options.addOption(SerivceNameOption);
options.addOption(SmithyModelPathOption);
final CommandLineParser parser = new DefaultParser();
final CommandLine parsed = parser.parse(options, args);
return new CliOptions(parsed);
Expand All @@ -36,9 +45,7 @@ public String GetServiceName() throws ParseException {
return this.commandLine.getOptionValue(SerivceNameOption);
}

public void PrintHelp() {
System.out.println("Could Not Find required args:");
Arrays.stream(this.commandLine.getOptions())
.forEach(System.out::println);
public String GetSmithyModelPath() throws ParseException {
return this.commandLine.getOptionValue(SmithyModelPathOption);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -80,9 +79,8 @@ public static final class Failure {
private final File smithyFile;
private final String serviceName;

public static SmithyParser BuildFromServiceName(final String serviceName) throws URISyntaxException {
URL resource = Thread.currentThread().getContextClassLoader().getResource(RESOURCE_SMITHY_DIR);
final Path path = Paths.get(Objects.requireNonNull(resource).toURI());
public static SmithyParser BuildFromServiceName(final String serviceName, final String smithyModelPath) throws URISyntaxException {
final Path path = Path.of(smithyModelPath);
try (final Stream<Path> paths = Files.walk(path)) {
final File smithyFile = paths.filter(file -> file.toString().contains(serviceName))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class main {
public static void main(String[] args) {
try {
final CliOptions options = CliOptions.BuildFromInput(args);
String serviceName = options.GetServiceName();
final SmithyParser parser = SmithyParser.BuildFromServiceName(serviceName);
final SmithyParser parser = SmithyParser.BuildFromServiceName(options.GetServiceName(),
options.GetSmithyModelPath());
parser.GenerateTests();
} catch (Exception e) {
System.out.println("Failed to generate code: " + e.getMessage());
Expand Down

0 comments on commit 0b497bd

Please sign in to comment.