15
15
package command
16
16
17
17
import (
18
- "bytes"
19
- "io"
18
+ "net/url"
20
19
"os"
21
20
"strings"
22
21
@@ -25,7 +24,7 @@ import (
25
24
)
26
25
27
26
type 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."`
29
28
From string `help:"Input file format. Possible values: ${enum}." enum:"auto, geojson, geoparquet, parquet" default:"auto"`
30
29
Output string `arg:"" optional:"" name:"output" help:"Output file. If not provided, output is written to stdout." type:"path"`
31
30
To string `help:"Output file format. Possible values: ${enum}." enum:"auto, geojson, geoparquet" default:"auto"`
@@ -64,14 +63,17 @@ func parseFormatType(format string) FormatType {
64
63
return ft
65
64
}
66
65
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" ) {
69
71
return GeoJSONType
70
72
}
71
- if strings .HasSuffix (filename , ".gpq" ) || strings .HasSuffix (filename , ".geoparquet" ) {
73
+ if strings .HasSuffix (resource , ".gpq" ) || strings .HasSuffix (resource , ".geoparquet" ) {
72
74
return GeoParquetType
73
75
}
74
- if strings .HasSuffix (filename , ".pq" ) || strings .HasSuffix (filename , ".parquet" ) {
76
+ if strings .HasSuffix (resource , ".pq" ) || strings .HasSuffix (resource , ".parquet" ) {
75
77
return ParquetType
76
78
}
77
79
return UnknownType
@@ -116,20 +118,9 @@ func (c *ConvertCmd) Run() error {
116
118
return NewCommandError ("could not determine input format for %s" , inputSource )
117
119
}
118
120
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 )
133
124
}
134
125
135
126
var output * os.File
0 commit comments