mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-17 16:38:54 +00:00
Support markdown format on input (#1478)
* Support markdown on input * unit-test files * doc mods * Unit-test cases for I/O-format keystroke-savers * -i/-o md as well as -i/-o markdown
This commit is contained in:
parent
2abb9b4729
commit
af021f28d7
243 changed files with 803 additions and 114 deletions
|
|
@ -762,6 +762,9 @@ var FileFormatFlagSection = FlagSection{
|
|||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
CheckArgCount(args, *pargi, argc, 2)
|
||||
options.ReaderOptions.InputFileFormat = args[*pargi+1]
|
||||
if options.ReaderOptions.InputFileFormat == "md" {
|
||||
options.ReaderOptions.InputFileFormat = "markdown" // alias
|
||||
}
|
||||
*pargi += 2
|
||||
},
|
||||
},
|
||||
|
|
@ -823,6 +826,9 @@ var FileFormatFlagSection = FlagSection{
|
|||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
CheckArgCount(args, *pargi, argc, 2)
|
||||
options.WriterOptions.OutputFileFormat = args[*pargi+1]
|
||||
if options.WriterOptions.OutputFileFormat == "md" {
|
||||
options.WriterOptions.OutputFileFormat = "markdown" // alias
|
||||
}
|
||||
*pargi += 2
|
||||
},
|
||||
},
|
||||
|
|
@ -896,8 +902,19 @@ var FileFormatFlagSection = FlagSection{
|
|||
},
|
||||
|
||||
{
|
||||
name: "--omd",
|
||||
help: "Use markdown-tabular format for output data.",
|
||||
name: "--imd",
|
||||
altNames: []string{"--imarkdown"},
|
||||
help: "Use markdown-tabular format for input data.",
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "--omd",
|
||||
altNames: []string{"--omarkdown"},
|
||||
help: "Use markdown-tabular format for output data.",
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
|
|
@ -1151,19 +1168,19 @@ var FileFormatFlagSection = FlagSection{
|
|||
func FormatConversionKeystrokeSaverPrintInfo() {
|
||||
fmt.Println(`As keystroke-savers for format-conversion you may use the following.
|
||||
The letters c, t, j, l, d, n, x, p, and m refer to formats CSV, TSV, DKVP, NIDX,
|
||||
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively. Note that markdown
|
||||
format is available for output only.
|
||||
JSON, JSON Lines, XTAB, PPRINT, and markdown, respectively.
|
||||
|
||||
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
|
||||
+--------+-------+-------+--------+--------+--------+--------+--------+----------+
|
||||
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
|
||||
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
|
||||
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
|
||||
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
|
||||
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
|
||||
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
|
||||
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
|
||||
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |`)
|
||||
| In\out | CSV | TSV | JSON | JSONL | DKVP | NIDX | XTAB | PPRINT | Markdown |
|
||||
+----------+-------+-------+--------+--------+--------+--------+--------+--------+----------|
|
||||
| CSV | | --c2t | --c2j | --c2l | --c2d | --c2n | --c2x | --c2p | --c2m |
|
||||
| TSV | --t2c | | --t2j | --t2l | --t2d | --t2n | --t2x | --t2p | --t2m |
|
||||
| JSON | --j2c | --j2t | | --j2l | --j2d | --j2n | --j2x | --j2p | --j2m |
|
||||
| JSONL | --l2c | --l2t | | | --l2d | --l2n | --l2x | --l2p | --l2m |
|
||||
| DKVP | --d2c | --d2t | --d2j | --d2l | | --d2n | --d2x | --d2p | --d2m |
|
||||
| NIDX | --n2c | --n2t | --n2j | --n2l | --n2d | | --n2x | --n2p | --n2m |
|
||||
| XTAB | --x2c | --x2t | --x2j | --x2l | --x2d | --x2n | | --x2p | --x2m |
|
||||
| PPRINT | --p2c | --p2t | --p2j | --p2l | --p2d | --p2n | --p2x | | --p2m |
|
||||
| Markdown | --m2c | --m2t | --m2j | --m2l | --m2d | --m2n | --m2x | --m2p | |`)
|
||||
}
|
||||
|
||||
func init() { FormatConversionKeystrokeSaverFlagSection.Sort() }
|
||||
|
|
@ -1288,6 +1305,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--c2m",
|
||||
help: "Use CSV for input, markdown-tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "csv"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--c2b",
|
||||
help: "Use CSV for input, PPRINT with `--barred` for output.",
|
||||
|
|
@ -1408,6 +1437,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--t2m",
|
||||
help: "Use TSV for input, markdown tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "tsv"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--t2b",
|
||||
help: "Use TSV for input, PPRINT with `--barred` for output.",
|
||||
|
|
@ -1527,6 +1568,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--d2m",
|
||||
help: "Use DKVP for input, markdown tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "dkvp"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--d2b",
|
||||
help: "Use DKVP for input, PPRINT with `--barred` for output.",
|
||||
|
|
@ -1642,6 +1695,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--n2m",
|
||||
help: "Use NIDX for input, markdown tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "nidx"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--n2b",
|
||||
help: "Use NIDX for input, PPRINT with `--barred` for output.",
|
||||
|
|
@ -1756,6 +1821,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--j2m",
|
||||
help: "Use JSON for input, markdown-tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "json"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--j2b",
|
||||
help: "Use JSON for input, PPRINT with --barred for output.",
|
||||
|
|
@ -1867,6 +1944,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--l2m",
|
||||
help: "Use JSON Lines for input, markdown-tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "json"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--l2b",
|
||||
help: "Use JSON Lines for input, PPRINT with --barred for output.",
|
||||
|
|
@ -2023,6 +2112,115 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "--m2c",
|
||||
help: "Use markdown-tabular for input, CSV for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "csv"
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
options.WriterOptions.orsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2t",
|
||||
help: "Use markdown-tabular for input, TSV for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "tsv"
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2d",
|
||||
help: "Use markdown-tabular for input, DKVP for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "dkvp"
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2n",
|
||||
help: "Use markdown-tabular for input, NIDX for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "nidx"
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2j",
|
||||
help: "Use markdown-tabular for input, JSON for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "json"
|
||||
options.WriterOptions.WrapJSONOutputInOuterList = true
|
||||
options.WriterOptions.JSONOutputMultiline = true
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2l",
|
||||
help: "Use markdown-tabular for input, JSON Lines for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "json"
|
||||
options.WriterOptions.WrapJSONOutputInOuterList = false
|
||||
options.WriterOptions.JSONOutputMultiline = false
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2x",
|
||||
help: "Use markdown-tabular for input, XTAB for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "xtab"
|
||||
options.ReaderOptions.ifsWasSpecified = true
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--m2p",
|
||||
help: "Use markdown-tabular for input, PPRINT for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "markdown"
|
||||
options.WriterOptions.OutputFileFormat = "pprint"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "--x2c",
|
||||
help: "Use XTAB for input, CSV for output.",
|
||||
|
|
@ -2112,6 +2310,18 @@ var FormatConversionKeystrokeSaverFlagSection = FlagSection{
|
|||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--x2m",
|
||||
help: "Use XTAB for input, markdown-tabular for output.",
|
||||
// For format-conversion keystroke-savers, a matrix is plenty -- we don't
|
||||
// need to print a tedious 60-line list.
|
||||
suppressFlagEnumeration: true,
|
||||
parser: func(args []string, argc int, pargi *int, options *TOptions) {
|
||||
options.ReaderOptions.InputFileFormat = "xtab"
|
||||
options.WriterOptions.OutputFileFormat = "markdown"
|
||||
*pargi += 1
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "--x2b",
|
||||
help: "Use XTAB for input, PPRINT with `--barred` for output.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue