Skip to content

Commit

Permalink
Add arg to specify input configuration in export
Browse files Browse the repository at this point in the history
Previously, the `export` command would always read its input from
`3rdparty.yaml`. This commit adds a new parameter, `--input-path`, which
configures where to read the 3rdparty configuration from.

If the input file name ends with `.json`, then a JSON parser is used,
instead of the default YAML parser.
  • Loading branch information
Duhemm committed Feb 15, 2023
1 parent d1d0f0d commit f13aefa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import multiversion.resolvers.Sha256
@CommandName("export")
case class ExportCommand(
lint: Boolean = true,
inputPath: Path = Paths.get("3rdparty.yaml"),
outputPath: Path = Paths.get("/tmp", "jvm_deps.bzl"),
cache: Option[Path] = None,
@Inline
Expand Down Expand Up @@ -165,13 +166,15 @@ case class ExportCommand(

private def parseThirdpartyConfig(): Result[ThirdpartyConfig] = {
val configPath =
app.env.workingDirectory.resolve("3rdparty.yaml")
app.env.workingDirectory.resolve(inputPath)
if (!Files.isRegularFile(configPath)) {
ErrorResult(
Diagnostic.error(
s"no such file: $configPath\n\tTo fix this problem, change your working directory or create this file"
)
)
} else if (configPath.getFileName.toString.endsWith(".json")) {
ThirdpartyConfig.parseJson(Input.path(configPath))
} else {
ThirdpartyConfig.parseYaml(Input.path(configPath))
}
Expand Down
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ load("@maven//:jvm_deps.bzl", "load_jvm_deps")
load_jvm_deps()
```

### YAML
### YAML or JSON

If you prefer to configure the dependencies in one file, create `3rdparty.yaml`
at the root of monorepo instead
Expand All @@ -131,6 +131,13 @@ runt the following inside the `multiversion-example/` directory:
$ multiversion export --output-path=3rdparty/jvm_deps.bzl
```

You can also specify a different path or format for the input configuration using
`--input-path`:

```sh
$ multiversion export --input-path=config/3rdparty.json --output-path=3rdparty/jvm_deps.bzl
```

### Pants

```sh
Expand Down

0 comments on commit f13aefa

Please sign in to comment.