Skip to content

Commit 9175002

Browse files
authored
cli: Add --output-format=PARTIQL_PRETTY for non-interactive use (#349)
1 parent 4bbdc7e commit 9175002

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

cli/src/org/partiql/cli/Cli.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ package org.partiql.cli
1616

1717
import com.amazon.ion.*
1818
import com.amazon.ion.system.*
19+
import java.io.*
1920
import org.partiql.cli.OutputFormat.*
2021
import org.partiql.lang.*
2122
import org.partiql.lang.eval.*
22-
import java.io.*
23+
import org.partiql.lang.util.ConfigurableExprValueFormatter
2324

2425
/**
2526
* TODO builder, kdoc
@@ -46,6 +47,9 @@ internal class Cli(private val valueFactory: ExprValueFactory,
4647
ION_TEXT -> valueFactory.ion.newTextWriter(output).use { printIon(it, result) }
4748
ION_BINARY -> valueFactory.ion.newBinaryWriter(output).use { printIon(it, result) }
4849
PARTIQL -> OutputStreamWriter(output).use { it.write(result.toString()) }
50+
PARTIQL_PRETTY -> OutputStreamWriter(output).use {
51+
ConfigurableExprValueFormatter.pretty.formatTo(result, it)
52+
}
4953
}
5054
}
5155
}

cli/src/org/partiql/cli/main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private val formatter = object : BuiltinHelpFormatter(120, 2) {
6262
}
6363

6464
enum class OutputFormat {
65-
ION_TEXT, ION_BINARY, PARTIQL
65+
ION_TEXT, ION_BINARY, PARTIQL, PARTIQL_PRETTY
6666
}
6767

6868
// opt parser options
@@ -108,7 +108,7 @@ private val outputFormatOpt = optParser.acceptsAll(listOf("output-format", "of")
108108
* * -q --query: PartiQL query
109109
* * -i --input: input file, default STDIN
110110
* * -o --output: output file, default STDOUT
111-
* * -of --output-format: output format, ION_TEXT, ION_BINARY and PARTIQL (default)
111+
* * -of --output-format: ION_TEXT, ION_BINARY, PARTIQL (default), PARTIQL_PRETTY
112112
*/
113113
fun main(args: Array<String>) = try {
114114
optParser.formatHelpWith(formatter)

docs/user/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Option Description
2525
-i, --input <File> input file, requires the query option (default: stdin)
2626
-o, --output <File> output file, requires the query option (default: stdout)
2727
--of, --output-format <OutputFormat: output format, requires the query option (default: PARTIQL)
28-
(ION_TEXT|ION_BINARY|PARTIQL)>
28+
(ION_TEXT|ION_BINARY|PARTIQL|PARTIQL_PRETTY)>
2929
-q, --query <String> PartiQL query, triggers non interactive mode
3030
```
3131

0 commit comments

Comments
 (0)