Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8] support for sql file input as arguments #45

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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