Skip to content

Commit

Permalink
fix: will now work even if "AWS_CLI_AUTO_PROMPT=on" is set in the cur…
Browse files Browse the repository at this point in the history
…rent shell (#2)

feat: added init project command for python and typescript cdk projects
chore: upgraded dependencies
chore: set version 2.5.9
  • Loading branch information
oscarostrand committed Apr 21, 2023
1 parent ba0db97 commit 266f702
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.6</version>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>io.micronaut.picocli</groupId>
Expand Down Expand Up @@ -285,13 +285,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.4.0</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.4.0</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/se/attini/cli/AttiniCliCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void main(String[] args) {
public static class VersionProvider implements CommandLine.IVersionProvider {
public final static int MAJOR = 2;
public final static int MINOR = 5;
public final static int PATCH = 8;
public final static int PATCH = 9;

public static final String VERSION_STRING = MAJOR + "." + MINOR + "." + PATCH;

Expand Down
45 changes: 45 additions & 0 deletions src/main/java/se/attini/cli/init/InitCdkPythonCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

package se.attini.cli.init;


import static java.util.Objects.requireNonNull;
import static se.attini.cli.PrintItem.PrintType.SUCCESS;

import jakarta.inject.Inject;
import picocli.CommandLine;
import se.attini.cli.AttiniCliCommand;
import se.attini.cli.CliError;
import se.attini.cli.ConsolePrinter;
import se.attini.cli.ErrorResolver;
import se.attini.cli.PrintItem;
import se.attini.cli.global.DebugOption;
import se.attini.init.InitProjectService;

@CommandLine.Command(name = "cdk-python", versionProvider = AttiniCliCommand.VersionProvider.class, description = "Create a Python CDK project.")
public class InitCdkPythonCommand implements Runnable {

@CommandLine.Mixin
private DebugOption debugOption;
@SuppressWarnings("unused")
@CommandLine.Option(names = {"--help", "-h"}, description = "Show information about this command.", usageHelp = true)
private boolean help;
private final ConsolePrinter consolePrinter;

@Inject
public InitCdkPythonCommand(ConsolePrinter consolePrinter) {
this.consolePrinter = requireNonNull(consolePrinter, "consolePrinter");
}

@Override
public void run() {
try {
InitProjectService.initCdkPythons();
consolePrinter.print(PrintItem.message(SUCCESS,
"Successfully initialized Python CDK project"));
} catch (Exception e) {
CliError error = ErrorResolver.resolve(e);
consolePrinter.printError(error);
System.exit(error.getErrorCode().getExitCode());
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/se/attini/cli/init/InitCdkTypeScriptCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

package se.attini.cli.init;


import static java.util.Objects.requireNonNull;
import static se.attini.cli.PrintItem.PrintType.SUCCESS;

import jakarta.inject.Inject;
import picocli.CommandLine;
import se.attini.cli.AttiniCliCommand;
import se.attini.cli.CliError;
import se.attini.cli.ConsolePrinter;
import se.attini.cli.ErrorResolver;
import se.attini.cli.PrintItem;
import se.attini.cli.global.DebugOption;
import se.attini.init.InitProjectService;

@CommandLine.Command(name = "cdk-typescript", versionProvider = AttiniCliCommand.VersionProvider.class, description = "Create a TypeScript CDK project.")
public class InitCdkTypeScriptCommand implements Runnable {

@CommandLine.Mixin
private DebugOption debugOption;
@SuppressWarnings("unused")
@CommandLine.Option(names = {"--help", "-h"}, description = "Show information about this command.", usageHelp = true)
private boolean help;
private final ConsolePrinter consolePrinter;

@Inject
public InitCdkTypeScriptCommand(ConsolePrinter consolePrinter) {
this.consolePrinter = requireNonNull(consolePrinter, "consolePrinter");
}

@Override
public void run() {
try {
InitProjectService.initCdkTypeScript();
consolePrinter.print(PrintItem.message(SUCCESS,
"Successfully initialized TypeScript CDK project"));
} catch (Exception e) {
CliError error = ErrorResolver.resolve(e);
consolePrinter.printError(error);
System.exit(error.getErrorCode().getExitCode());
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/se/attini/cli/init/InitProjectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
subcommands = {InitHelloWorldCommand.class,
InitSkeletonCommand.class,
InitSimpleWebsiteCommand.class,
InitSamProjectCommand.class},
InitSamProjectCommand.class,
InitCdkTypeScriptCommand.class,
InitCdkPythonCommand.class},
description = "Create different template projects.")
public class InitProjectCommand {

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/se/attini/init/InitProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public static void initHelloWorld() {
initProject("init-project-hello-world");
}

public static void initCdkPythons(){
initProject("init-project-cdk-python");
}

public static void initCdkTypeScript(){
initProject("init-project-cdk-typescript");
}

public static void initSamProject(){
initProject("sam-project");
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/se/attini/profile/ProfileFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ private Region getProfileRegion(Profile profile) {
return Region.create(awsRegion);
}
try {
Process process = Runtime.getRuntime()
.exec("aws configure get region --profile " + profile.getProfileName());
Process process = new ProcessBuilder()
.command(List.of(environmentVariables.getShell(),
"-c",
"export AWS_CLI_AUTO_PROMPT=off && aws configure get region --profile " + profile.getProfileName()))
.start();
String region = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine();
if (region == null) {
throw new IllegalArgumentException("No region is configured for profile =" + profile.getProfileName());
Expand All @@ -63,7 +66,11 @@ private Region getProfileRegion() {
return Region.create(awsRegion);
}
try {
Process process = Runtime.getRuntime().exec("aws configure get region");
Process process = new ProcessBuilder()
.command(List.of(environmentVariables.getShell(),
"-c",
"export AWS_CLI_AUTO_PROMPT=off && aws configure get region"))
.start();
String region = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine();
if (region == null) {
throw new IllegalArgumentException("No default region is configured");
Expand All @@ -77,7 +84,7 @@ private Region getProfileRegion() {

public Region getRegion() {

return regionCache.computeIfAbsent(globalConfig.getProfile().orElse(Profile.create("Default")), profile -> {
return regionCache.computeIfAbsent(globalConfig.getProfile().orElse(Profile.create("Default")), profile -> {
if (globalConfig.getRegion().isPresent()) {
return globalConfig.getRegion().get();
}
Expand Down

0 comments on commit 266f702

Please sign in to comment.