mirror of https://github.com/tidwall/tile38.git
Added -x flag to tile38-cli
The new -x flag allows for passing large objects from STDIN. tile38-cli -x SET cities tempe OBJECT </path/to/file.geojson See #634 for more information
This commit is contained in:
parent
fcdb469ee4
commit
83cedde2df
|
@ -50,6 +50,7 @@ var (
|
||||||
raw bool
|
raw bool
|
||||||
noprompt bool
|
noprompt bool
|
||||||
tty bool
|
tty bool
|
||||||
|
stdin bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func showHelp() bool {
|
func showHelp() bool {
|
||||||
|
@ -68,6 +69,7 @@ func showHelp() bool {
|
||||||
fmt.Fprintf(os.Stdout, " --json Use JSON output formatting (default is JSON output)\n")
|
fmt.Fprintf(os.Stdout, " --json Use JSON output formatting (default is JSON output)\n")
|
||||||
fmt.Fprintf(os.Stdout, " -h <hostname> Server hostname (default: %s)\n", hostname)
|
fmt.Fprintf(os.Stdout, " -h <hostname> Server hostname (default: %s)\n", hostname)
|
||||||
fmt.Fprintf(os.Stdout, " -p <port> Server port (default: %d)\n", port)
|
fmt.Fprintf(os.Stdout, " -p <port> Server port (default: %d)\n", port)
|
||||||
|
fmt.Fprintf(os.Stdout, " -x Read last argument from STDIN.\n")
|
||||||
fmt.Fprintf(os.Stdout, "\n")
|
fmt.Fprintf(os.Stdout, "\n")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -117,6 +119,8 @@ func parseArgs() bool {
|
||||||
output = "resp"
|
output = "resp"
|
||||||
case "--json":
|
case "--json":
|
||||||
output = "json"
|
output = "json"
|
||||||
|
case "-x":
|
||||||
|
stdin = true
|
||||||
case "-h":
|
case "-h":
|
||||||
hostname = readArg(arg)
|
hostname = readArg(arg)
|
||||||
case "-p":
|
case "-p":
|
||||||
|
@ -128,6 +132,20 @@ func parseArgs() bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oneCommand = strings.Join(args, " ")
|
oneCommand = strings.Join(args, " ")
|
||||||
|
if stdin {
|
||||||
|
data, err := io.ReadAll(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
println(err)
|
||||||
|
}
|
||||||
|
if !gjson.ValidBytes(data) {
|
||||||
|
fmt.Fprintf(os.Stderr, "Invalid STDIN: Not JSON\n")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
arg := strings.Replace(string(data), "\r", "", -1)
|
||||||
|
arg = strings.Replace(arg, "\n", "", -1)
|
||||||
|
arg = strings.Replace(arg, "'", "\\'", -1)
|
||||||
|
oneCommand += " '" + arg + "'"
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue