mirror of
https://github.com/therootcompany/golib.git
synced 2025-10-30 12:42:51 +00:00
feat(gsheet2env): add -d to change delimiter
This commit is contained in:
parent
f882bfc139
commit
7513e62a6c
@ -22,12 +22,19 @@ func isValidKey(key string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
delimString := flag.String("d", ",", "field delimiter to use for output file ('\\t' for tab, '^_' for Unit Separator, etc)")
|
||||||
noShebang := flag.Bool("no-shebang", false, "don't begin the file with #!/bin/sh")
|
noShebang := flag.Bool("no-shebang", false, "don't begin the file with #!/bin/sh")
|
||||||
noHeader := flag.Bool("no-header", false, "treat all non-comment rows as ENVs - don't expect a header")
|
noHeader := flag.Bool("no-header", false, "treat all non-comment rows as ENVs - don't expect a header")
|
||||||
noExport := flag.Bool("no-export", false, "disable export prefix")
|
noExport := flag.Bool("no-export", false, "disable export prefix")
|
||||||
outputFile := flag.String("o", "-", "path to output env file (default: stdout)")
|
outputFile := flag.String("o", "-", "path to output env file (default: stdout)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
delim, err := gsheet2csv.DecodeDelimiter(*delimString)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error decoding output delimiter: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// Require Google Sheet URL as argument
|
// Require Google Sheet URL as argument
|
||||||
if len(flag.Args()) != 1 {
|
if len(flag.Args()) != 1 {
|
||||||
fmt.Fprintf(os.Stderr, "Error: exactly one Google Sheet URL or path is required\n")
|
fmt.Fprintf(os.Stderr, "Error: exactly one Google Sheet URL or path is required\n")
|
||||||
@ -54,6 +61,7 @@ func main() {
|
|||||||
gsr := gsheet2csv.NewReaderFrom(gsheetURLOrPath)
|
gsr := gsheet2csv.NewReaderFrom(gsheetURLOrPath)
|
||||||
// preserves comment-looking data (and actual comments)
|
// preserves comment-looking data (and actual comments)
|
||||||
gsr.Comment = 0
|
gsr.Comment = 0
|
||||||
|
gsr.Comma = delim
|
||||||
gsr.FieldsPerRecord = -1
|
gsr.FieldsPerRecord = -1
|
||||||
|
|
||||||
if !*noShebang {
|
if !*noShebang {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user