Skip to content

Commit

Permalink
Clean up CLI main method
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinRay97 committed Nov 12, 2024
1 parent 7615e2e commit 751d8d5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions ndc-cli/src/main/kotlin/io/hasura/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.hasura.ndc.common.ConnectorConfiguration
import picocli.CommandLine
import picocli.CommandLine.*
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.attribute.PosixFilePermissions
import kotlin.system.exitProcess

Expand Down Expand Up @@ -58,14 +58,17 @@ class CLI {
)
schemas: List<String>?
) {
val configFilePath = ConnectorConfiguration.Loader.getConfigFilePath()
val existingConfig = ConnectorConfiguration.Loader.config
val file = File(outfile)

println("Checking for configuration file at $configFilePath")
if (existingConfig == ConnectorConfiguration()) {
println("Non-existent or empty configuration file detected")
} else {
println("Existing configuration file detected")
println("Checking for configuration file at ${file.absolutePath}")
val existingConfig = file.let {
if (it.exists()) {
println("Existing configuration file detected")
mapper.readValue(it, ConnectorConfiguration::class.java)
} else {
println("Non-existent or empty configuration file detected")
ConnectorConfiguration()
}
}

val configGenerator = when (database) {
Expand All @@ -83,17 +86,14 @@ class CLI {
nativeQueries = existingConfig.nativeQueries
)

val outfilePath = Path.of(ConnectorConfiguration.Loader.CONFIG_DIRECTORY, outfile)
println("Writing configuration to file: $configFilePath")

val file = configFilePath.toFile()
try {
println("Writing configuration to ${file.absolutePath}")
mapper.writerWithDefaultPrettyPrinter().writeValue(file, mergedConfigWithNativeQueries)
} catch (e: Exception) {
println("Error writing configuration to file: ${e.message}")

val parentDir = file.parentFile
val permissions = Files.getPosixFilePermissions(parentDir.toPath())
val permissions = Files.getPosixFilePermissions(parentDir.toPath())
val posixPermissions = PosixFilePermissions.toString(permissions)

println("Parent directory: ${parentDir.absolutePath}")
Expand Down

0 comments on commit 751d8d5

Please sign in to comment.