Skip to content

Commit

Permalink
Write error to stderr, also return proper exit code #9
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jun 19, 2020
1 parent d3c1870 commit 279df56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
23 changes: 0 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,18 @@
<version>1.18.12</version>
<scope>provided</scope>
</dependency>

<!--
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>com.github.xonixx</groupId>
<artifactId>java-utils</artifactId>
<version>v0.9.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
<scope>test</scope>
</dependency>-->
</dependencies>

<build>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/github/jsqry/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void main(String[] args) {
}

if (cmd.hasOption(version.getLongOpt())) {
System.out.println(Constants.getFullVersion());
System.out.println(Constants.getVersion());
System.exit(0);
}

Expand Down Expand Up @@ -76,7 +76,10 @@ public static void main(String[] args) {
Value doWork = context.eval("js", "doWork");

String inputJsonStr = new String(System.in.readAllBytes(), StandardCharsets.UTF_8);
doWork.executeVoid(inputJsonStr, query);
Value result = doWork.execute(inputJsonStr, query);
if (!result.asBoolean()) {
System.exit(1);
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ function doWork(jsonStr, queryStr) {
try {
json = JSON.parse(jsonStr);
} catch (e) {
print('error: Wrong JSON');
return
console.error('error: Wrong JSON');
return false;
}
let res;
try {
res = jsqry.query(json, queryStr);
} catch (e) {
print('error: ' + e);
return
console.error('error: ' + e);
return false;
}
print(JSON.stringify(res, null, 2));
console.info(JSON.stringify(res, null, 2));
return true;
}

0 comments on commit 279df56

Please sign in to comment.