1515package command
1616
1717import (
18- "bytes"
19- "io"
18+ "net/url"
2019 "os"
2120 "strings"
2221
@@ -25,7 +24,7 @@ import (
2524)
2625
2726type ConvertCmd struct {
28- Input string `arg:"" optional:"" name:"input" help:"Input file. If not provided, input is read from stdin." type:"path "`
27+ Input string `arg:"" optional:"" name:"input" help:"Input file path or URL . If not provided, input is read from stdin."`
2928 From string `help:"Input file format. Possible values: ${enum}." enum:"auto, geojson, geoparquet, parquet" default:"auto"`
3029 Output string `arg:"" optional:"" name:"output" help:"Output file. If not provided, output is written to stdout." type:"path"`
3130 To string `help:"Output file format. Possible values: ${enum}." enum:"auto, geojson, geoparquet" default:"auto"`
@@ -64,14 +63,17 @@ func parseFormatType(format string) FormatType {
6463 return ft
6564}
6665
67- func getFormatType (filename string ) FormatType {
68- if strings .HasSuffix (filename , ".json" ) || strings .HasSuffix (filename , ".geojson" ) {
66+ func getFormatType (resource string ) FormatType {
67+ if u , err := url .Parse (resource ); err == nil {
68+ resource = u .Path
69+ }
70+ if strings .HasSuffix (resource , ".json" ) || strings .HasSuffix (resource , ".geojson" ) {
6971 return GeoJSONType
7072 }
71- if strings .HasSuffix (filename , ".gpq" ) || strings .HasSuffix (filename , ".geoparquet" ) {
73+ if strings .HasSuffix (resource , ".gpq" ) || strings .HasSuffix (resource , ".geoparquet" ) {
7274 return GeoParquetType
7375 }
74- if strings .HasSuffix (filename , ".pq" ) || strings .HasSuffix (filename , ".parquet" ) {
76+ if strings .HasSuffix (resource , ".pq" ) || strings .HasSuffix (resource , ".parquet" ) {
7577 return ParquetType
7678 }
7779 return UnknownType
@@ -116,20 +118,9 @@ func (c *ConvertCmd) Run() error {
116118 return NewCommandError ("could not determine input format for %s" , inputSource )
117119 }
118120
119- var input ReaderAtSeeker
120- if inputSource == "" {
121- data , err := io .ReadAll (os .Stdin )
122- if err != nil {
123- return NewCommandError ("trouble reading from stdin: %w" , err )
124- }
125- input = bytes .NewReader (data )
126- } else {
127- i , readErr := os .Open (inputSource )
128- if readErr != nil {
129- return NewCommandError ("failed to read from %q: %w" , inputSource , readErr )
130- }
131- defer i .Close ()
132- input = i
121+ input , inputErr := readerFromInput (inputSource )
122+ if inputErr != nil {
123+ return NewCommandError ("trouble getting a reader from %q: %w" , c .Input , inputErr )
133124 }
134125
135126 var output * os.File
0 commit comments