Skip to content

Commit a42e168

Browse files
authored
add-icaro-new-here-command (#27)
1 parent ff5dc43 commit a42e168

File tree

5 files changed

+190
-2
lines changed

5 files changed

+190
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.iml
2+
.DS_Store
3+
.idea/
4+
target/

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Coming soon
2-
Icaro package manager
1+
# Icaro package manager

pom.xml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.icaro</groupId>
5+
<artifactId>cli</artifactId>
6+
<version>0.1</version>
7+
<packaging>jar</packaging>
8+
<name>Icaro programming language CLI</name>
9+
<url>http://maven.apache.org</url>
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<kotlin.version>1.7.20</kotlin.version>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.google.code.gson</groupId>
19+
<artifactId>gson</artifactId>
20+
<version>2.10</version>
21+
<scope>compile</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>info.picocli</groupId>
25+
<artifactId>picocli</artifactId>
26+
<version>4.6.3</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.jetbrains.kotlin</groupId>
30+
<artifactId>kotlin-stdlib-jdk8</artifactId>
31+
<version>${kotlin.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jetbrains.kotlin</groupId>
35+
<artifactId>kotlin-test</artifactId>
36+
<version>${kotlin.version}</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<!-- Testing Dependencies -->
40+
<dependency>
41+
<groupId>org.assertj</groupId>
42+
<artifactId>assertj-core</artifactId>
43+
<version>3.23.1</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter-api</artifactId>
49+
<version>5.9.0</version>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-engine</artifactId>
55+
<version>5.9.0</version>
56+
<scope>test</scope>
57+
</dependency>
58+
</dependencies>
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.jetbrains.kotlin</groupId>
63+
<artifactId>kotlin-maven-plugin</artifactId>
64+
<version>${kotlin.version}</version>
65+
<executions>
66+
<execution>
67+
<id>compile</id>
68+
<phase>compile</phase>
69+
<goals>
70+
<goal>compile</goal>
71+
</goals>
72+
<configuration>
73+
<sourceDirs>
74+
<source>src/main/kotlin</source>
75+
</sourceDirs>
76+
</configuration>
77+
</execution>
78+
<execution>
79+
<id>test-compile</id>
80+
<phase>test-compile</phase>
81+
<goals>
82+
<goal>test-compile</goal>
83+
</goals>
84+
<configuration>
85+
<sourceDirs>
86+
<source>src/test/kotlin</source>
87+
</sourceDirs>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-assembly-plugin</artifactId>
95+
<version>3.3.0</version>
96+
<configuration>
97+
<descriptorRefs>
98+
<descriptorRef>jar-with-dependencies</descriptorRef>
99+
</descriptorRefs>
100+
<archive>
101+
<manifest>
102+
<mainClass>MainKt</mainClass>
103+
</manifest>
104+
</archive>
105+
</configuration>
106+
<executions>
107+
<execution>
108+
<id>simple-command</id>
109+
<phase>package</phase>
110+
<goals>
111+
<goal>single</goal>
112+
</goals>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-surefire-plugin</artifactId>
119+
<version>2.22.1</version>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package commands
2+
3+
import com.google.gson.GsonBuilder
4+
import picocli.CommandLine
5+
import java.io.File
6+
import java.nio.file.Files
7+
import java.nio.file.Path
8+
import java.nio.file.Paths
9+
10+
@CommandLine.Command(name = "new-here", description = ["the current directory will become an Icaro project"])
11+
class NewHere : Runnable {
12+
13+
private fun createDependenciesFile(path: String) {
14+
File(path).delete()
15+
16+
val depsInJson = GsonBuilder().setPrettyPrinting().create().toJson(
17+
mapOf(
18+
"langVersion" to System.getenv("ICARO_LANG_VERSION"),
19+
"cliVersion" to System.getenv("ICARO_CLI_VERSION")
20+
)
21+
)
22+
23+
File(path).writeText(depsInJson)
24+
}
25+
26+
private fun createSourceDir(pathToSrcDir: String, pathToMainFile: String) {
27+
File(pathToSrcDir).deleteRecursively()
28+
29+
Files.createDirectory(Path.of(pathToSrcDir))
30+
File("$pathToSrcDir${File.separator}$pathToMainFile").writeText("")
31+
}
32+
33+
private fun createBinariesDir(pathToBinDir: String, pathToClassesDir: String) {
34+
File(pathToBinDir).deleteRecursively()
35+
36+
Files.createDirectory(Path.of(pathToBinDir))
37+
Files.createDirectory(Path.of("$pathToBinDir${File.separator}$pathToClassesDir"))
38+
}
39+
40+
override fun run() {
41+
val currentDir = Paths.get("").toAbsolutePath().toString()
42+
43+
createDependenciesFile("$currentDir${File.separator}dependencies.json")
44+
createSourceDir("$currentDir${File.separator}src", "main.ic")
45+
createBinariesDir("$currentDir${File.separator}.bin", "classes")
46+
}
47+
}

src/main/kotlin/main.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import commands.NewHere
2+
import picocli.CommandLine
3+
import picocli.CommandLine.*
4+
import kotlin.system.exitProcess
5+
6+
@Command(
7+
name = "icaro",
8+
subcommands = [NewHere::class, HelpCommand::class],
9+
description = ["The Icaro programming language CLI"]
10+
)
11+
class Icaro
12+
13+
fun main(args: Array<String>) {
14+
exitProcess(CommandLine(Icaro()).execute(*args))
15+
}

0 commit comments

Comments
 (0)