11package com.delphix.yamlparser
22
3+ import com.github.ajalt.clikt.core.CliktCommand
4+ import com.github.ajalt.clikt.parameters.options.*
5+ import io.github.cdimascio.dotenv.dotenv as Dotenv
6+
37import com.delphix.yamlparser.sdk.Delphix as Delphix
48import com.delphix.yamlparser.sdk.Http as Http
59
@@ -41,13 +45,20 @@ object Parser {
4145 return event
4246 }
4347
44- fun loadEnvs (): Map <String , String > {
45- val gitBranch: String = System .getenv(" GIT_BRANCH" ) ? : throw IllegalArgumentException (" GIT_BRANCH Environment Variable Required." )
46- val gitCommit: String = System .getenv(" GIT_COMMIT" ) ? : throw IllegalArgumentException (" GIT_COMMIT Environment Variable Required." )
47- val gitEvent = System .getenv(" GIT_EVENT" ) ? : loadEventFromPayload()
48- val delphixEngine: String = System .getenv(" DELPHIX_ENGINE" ) ? : throw IllegalArgumentException (" DELPHIX_ENGINE Environment Variable Required." )
49- val delphixUser: String = System .getenv(" DELPHIX_USER" ) ? : throw IllegalArgumentException (" DELPHIX_USER Environment Variable Required." )
50- val delphixPass: String = System .getenv(" DELPHIX_PASS" ) ? : throw IllegalArgumentException (" DELPHIX_PASS Environment Variable Required." )
48+ fun loadEnvs (env : String ): Map <String , String > {
49+
50+ val dotenv = Dotenv {
51+ filename = " $env "
52+ ignoreIfMalformed = true
53+ ignoreIfMissing = true
54+ }
55+
56+ val gitBranch: String = dotenv[" GIT_BRANCH" ] ? : throw IllegalArgumentException (" GIT_BRANCH Environment Variable Required." )
57+ val gitCommit: String = dotenv[" GIT_COMMIT" ] ? : throw IllegalArgumentException (" GIT_COMMIT Environment Variable Required." )
58+ val gitEvent = dotenv[" GIT_EVENT" ] ? : loadEventFromPayload()
59+ val delphixEngine: String = dotenv[" DELPHIX_ENGINE" ] ? : throw IllegalArgumentException (" DELPHIX_ENGINE Environment Variable Required." )
60+ val delphixUser: String = dotenv[" DELPHIX_USER" ] ? : throw IllegalArgumentException (" DELPHIX_USER Environment Variable Required." )
61+ val delphixPass: String = dotenv[" DELPHIX_PASS" ] ? : throw IllegalArgumentException (" DELPHIX_PASS Environment Variable Required." )
5162 return mapOf (
5263 " gitBranch" to gitBranch,
5364 " gitCommit" to gitCommit,
@@ -59,8 +70,11 @@ object Parser {
5970 )
6071 }
6172
62- @JvmStatic
63- fun main (args : Array <String >) {
73+ class Parse : CliktCommand () {
74+ val env: String by option(help= " Path to env file." ).default(" .env" )
75+
76+ override fun run (){
77+
6478 val file = File (" delphix.yaml" )
6579 try {
6680 fileExists(file)
@@ -77,7 +91,7 @@ object Parser {
7791 System .exit(0 )
7892 }
7993
80- val env: Map <String , String > = loadEnvs()
94+ val env: Map <String , String > = loadEnvs(env )
8195 val delphix: Delphix = Delphix (Http (env[" delphixEngine" ]? : " " ))
8296 val yaml: Yaml = Mapper ().mapYaml(contents)
8397 val runner: Runner = Runner (yaml, env, delphix)
@@ -89,6 +103,10 @@ object Parser {
89103 System .err.println (e.message)
90104 System .exit(0 )
91105 }
92-
106+
107+ }
93108 }
109+
110+ @JvmStatic
111+ fun main (args : Array <String >) = Parse ().main(args)
94112}
0 commit comments