Skip to content

Commit

Permalink
[#8] support for sql file input as arguments (#45)
Browse files Browse the repository at this point in the history
* #8 support for sql file input as arguments

* #8 update readme
  • Loading branch information
kdabir committed Jul 6, 2020
1 parent e6b29a7 commit a6dc2bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ If option `--in-dir` is used, all the `*.sql` files will be used for code genera
```
$ norm-codegen --help
Usage: norm-codegen [OPTIONS]
Usage: norm-codegen [OPTIONS] [SQLFILES]...
Generates Kotlin Source files for given SQL files using the Postgres
database connection
Expand All @@ -208,8 +208,8 @@ Options:
-p, --password TEXT Password (can use env var PG_PASSWORD)
-b, --base-path DIRECTORY relative path from this dir will be used to infer
package name
-f, --file FILE [Multiple] SQL files, the file path will be used
to infer package name
-f, --file FILE [Multiple] SQL files, the file path relative to
base path (-b) will be used to infer package name
-d, --in-dir DIRECTORY Dir containing .sql files, relative path from
this dir will be used to infer package name
-o, --out-dir DIRECTORY Output dir where source should be generated
Expand Down
14 changes: 11 additions & 3 deletions cli/src/main/kotlin/norm/cli/NormCli.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package norm.cli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.arguments.unique
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.file
import norm.api.NormApi
Expand Down Expand Up @@ -42,7 +45,12 @@ class NormCli : CliktCommand( // command name is inferred as norm-cli
.file(canBeFile = false, canBeDir = true, mustExist = true)
.default(File(".")) // Current working dir

private val inputFiles by option("-f", "--file", help = "[Multiple] SQL files, the file path will be used to infer package name")
private val inputFilesAsOpts by option("-f", "--file", help = "[Multiple] SQL files, the file path relative to base path (-b) will be used to infer package name")
.file(canBeFile = true, canBeDir = false, mustExist = true)
.multiple()
.unique()

private val sqlFiles by argument() // give meaningful name for CLI help message
.file(canBeFile = true, canBeDir = false, mustExist = true)
.multiple()
.unique()
Expand All @@ -67,8 +75,8 @@ class NormCli : CliktCommand( // command name is inferred as norm-cli
}
}

// If dir is provided, relativize to basePath
inputFiles.forEach { sqlFile ->
// if file list is explicitly provided, it is relative to basePath
(inputFilesAsOpts + sqlFiles).forEach { sqlFile ->
IO(sqlFile, basePath, outDir).process(normApi::generate)
}
}
Expand Down

0 comments on commit a6dc2bd

Please sign in to comment.