From 16d491f0ca567274969d904367b1fa9a632c0ec3 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Fri, 21 Aug 2020 15:07:43 +0200
Subject: [PATCH] Fix cmd output

---
 dist/index.js | 15 ++++++++++-----
 src/aws.ts    | 13 ++++++++-----
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 1e42442..a5d690d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -4099,13 +4099,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
     });
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getRegion = exports.parseCLIVersion = exports.getCLIVersion = exports.getCLICmdOutput = exports.getCLI = exports.isECR = void 0;
+exports.parseCLIVersion = exports.getCLIVersion = exports.getCLICmdOutput = exports.getCLI = exports.getRegion = exports.isECR = void 0;
 const semver = __importStar(__webpack_require__(383));
 const io = __importStar(__webpack_require__(436));
 const execm = __importStar(__webpack_require__(757));
 exports.isECR = (registry) => __awaiter(void 0, void 0, void 0, function* () {
     return registry.includes('amazonaws');
 });
+exports.getRegion = (registry) => __awaiter(void 0, void 0, void 0, function* () {
+    return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
+});
 exports.getCLI = () => __awaiter(void 0, void 0, void 0, function* () {
     return io.which('aws', true);
 });
@@ -4114,7 +4117,12 @@ exports.getCLICmdOutput = (args) => __awaiter(void 0, void 0, void 0, function*
         if (res.stderr != '' && !res.success) {
             throw new Error(res.stderr);
         }
-        return res.stdout;
+        else if (res.stderr != '') {
+            return res.stderr.trim();
+        }
+        else {
+            return res.stdout.trim();
+        }
     });
 });
 exports.getCLIVersion = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -4127,9 +4135,6 @@ exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function
     }
     return undefined;
 });
-exports.getRegion = (registry) => __awaiter(void 0, void 0, void 0, function* () {
-    return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
-});
 //# sourceMappingURL=aws.js.map
 
 /***/ })
diff --git a/src/aws.ts b/src/aws.ts
index 8f5c289..4a809bd 100644
--- a/src/aws.ts
+++ b/src/aws.ts
@@ -6,6 +6,10 @@ export const isECR = async (registry: string): Promise<boolean> => {
   return registry.includes('amazonaws');
 };
 
+export const getRegion = async (registry: string): Promise<string> => {
+  return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
+};
+
 export const getCLI = async (): Promise<string> => {
   return io.which('aws', true);
 };
@@ -14,8 +18,11 @@ export const getCLICmdOutput = async (args: string[]): Promise<string> => {
   return execm.exec(await getCLI(), args, true).then(res => {
     if (res.stderr != '' && !res.success) {
       throw new Error(res.stderr);
+    } else if (res.stderr != '') {
+      return res.stderr.trim();
+    } else {
+      return res.stdout.trim();
     }
-    return res.stdout;
   });
 };
 
@@ -30,7 +37,3 @@ export const parseCLIVersion = async (stdout: string): Promise<string | undefine
   }
   return undefined;
 };
-
-export const getRegion = async (registry: string): Promise<string> => {
-  return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
-};