Skip to content

Commit aa29abf

Browse files
dfa1claude
andcommitted
feat(cli): add cli module with inspect and import subcommands
Shade fat jar at target/vortex.jar. import derives output path from input filename; inspect delegates to VortexInspector. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ad9a472 commit aa29abf

5 files changed

Lines changed: 179 additions & 0 deletions

File tree

cli/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.github.dfa1.vortex</groupId>
8+
<artifactId>vortex-java</artifactId>
9+
<version>0.1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>cli</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.github.dfa1.vortex</groupId>
17+
<artifactId>csv</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.github.dfa1.vortex</groupId>
21+
<artifactId>reader</artifactId>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<finalName>vortex</finalName>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-shade-plugin</artifactId>
31+
<version>3.6.0</version>
32+
<executions>
33+
<execution>
34+
<phase>package</phase>
35+
<goals>
36+
<goal>shade</goal>
37+
</goals>
38+
<configuration>
39+
<shadedArtifactAttached>false</shadedArtifactAttached>
40+
<transformers>
41+
<transformer
42+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
43+
<mainClass>io.github.dfa1.vortex.cli.VortexCli</mainClass>
44+
<manifestEntries>
45+
<Enable-Native-Access>ALL-UNNAMED</Enable-Native-Access>
46+
</manifestEntries>
47+
</transformer>
48+
<transformer
49+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
50+
</transformers>
51+
<filters>
52+
<filter>
53+
<artifact>*:*</artifact>
54+
<excludes>
55+
<exclude>module-info.class</exclude>
56+
<exclude>META-INF/*.SF</exclude>
57+
<exclude>META-INF/*.DSA</exclude>
58+
<exclude>META-INF/*.RSA</exclude>
59+
</excludes>
60+
</filter>
61+
</filters>
62+
</configuration>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.dfa1.vortex.cli;
2+
3+
import io.github.dfa1.vortex.csv.CsvImporter;
4+
5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
9+
final class ImportCommand {
10+
11+
private ImportCommand() {
12+
}
13+
14+
static int run(String[] args) {
15+
if (args.length < 2 || args.length > 3) {
16+
System.err.println("usage: import <file.csv> [out.vortex]");
17+
return 1;
18+
}
19+
Path csvPath = Path.of(args[1]);
20+
if (!Files.exists(csvPath)) {
21+
System.err.println("file not found: " + csvPath);
22+
return 2;
23+
}
24+
Path vortexPath = args.length == 3 ? Path.of(args[2]) : deriveOutputPath(csvPath);
25+
try {
26+
CsvImporter.importCsv(csvPath, vortexPath);
27+
System.out.println("written: " + vortexPath);
28+
return 0;
29+
} catch (IOException e) {
30+
System.err.println("error: " + e.getMessage());
31+
return 3;
32+
}
33+
}
34+
35+
private static Path deriveOutputPath(Path csvPath) {
36+
String name = csvPath.getFileName().toString();
37+
if (name.endsWith(".csv")) {
38+
name = name.substring(0, name.length() - 4);
39+
}
40+
return csvPath.resolveSibling(name + ".vortex");
41+
}
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.dfa1.vortex.cli;
2+
3+
import io.github.dfa1.vortex.io.VortexInspector;
4+
import io.github.dfa1.vortex.io.VortexReader;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
10+
final class InspectCommand {
11+
12+
private InspectCommand() {
13+
}
14+
15+
static int run(String[] args) {
16+
if (args.length != 2) {
17+
System.err.println("usage: inspect <file.vortex>");
18+
return 1;
19+
}
20+
Path path = Path.of(args[1]);
21+
if (!Files.exists(path)) {
22+
System.err.println("file not found: " + path);
23+
return 2;
24+
}
25+
try (VortexReader reader = VortexReader.open(path)) {
26+
System.out.print(VortexInspector.inspect(reader));
27+
return 0;
28+
} catch (IOException e) {
29+
System.err.println("error: " + e.getMessage());
30+
return 3;
31+
}
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.github.dfa1.vortex.cli;
2+
3+
import java.io.PrintStream;
4+
5+
/// Entry point for the Vortex command-line tool.
6+
///
7+
/// Exit codes: 0 = success, 1 = usage error, 2 = file not found, 3 = decode error.
8+
public final class VortexCli {
9+
10+
private VortexCli() {
11+
}
12+
13+
public static void main(String[] args) {
14+
if (args.length == 0) {
15+
printUsage(System.err);
16+
System.exit(1);
17+
}
18+
int exit = switch (args[0]) {
19+
case "inspect" -> InspectCommand.run(args);
20+
case "import" -> ImportCommand.run(args);
21+
default -> {
22+
System.err.println("unknown subcommand: " + args[0]);
23+
printUsage(System.err);
24+
yield 1;
25+
}
26+
};
27+
System.exit(exit);
28+
}
29+
30+
static void printUsage(PrintStream out) {
31+
out.println("Usage: java -jar vortex.jar <subcommand> [args]");
32+
out.println(" inspect <file.vortex> print file structure");
33+
out.println(" import <file.csv> [out.vortex] convert CSV to Vortex");
34+
}
35+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<module>reader</module>
1515
<module>writer</module>
1616
<module>csv</module>
17+
<module>cli</module>
1718
<module>integration</module>
1819
<module>performance</module>
1920
</modules>

0 commit comments

Comments
 (0)