Skip to content

Commit

Permalink
upload command takes options flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Oct 7, 2022
1 parent d00b536 commit 52d1129
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ archives:
linux: Linux
windows: Windows
amd64: x86_64
format_overrides:
- goos: windows
format: zip
- goos: darwin
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
16 changes: 7 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ func main() {
os.Exit(1)
}

serveCmd := flag.NewFlagSet("serve", flag.ExitOnError)
port := serveCmd.String("p", "8080", "port to serve on")
cors := serveCmd.String("cors", "", "CORS allowed origin value")
cacheSize := serveCmd.Int("cache", 64, "Cache size in mb")

subpyramidCmd := flag.NewFlagSet("subpyramid", flag.ExitOnError)
cpuProfile := subpyramidCmd.Bool("profile", false, "profiling output")

switch os.Args[1] {
case "show":
pmtiles.Show(logger, os.Args)
case "serve":
serveCmd := flag.NewFlagSet("serve", flag.ExitOnError)
port := serveCmd.String("p", "8080", "port to serve on")
cors := serveCmd.String("cors", "", "CORS allowed origin value")
cacheSize := serveCmd.Int("cache", 64, "Cache size in mb")
serveCmd.Parse(os.Args[2:])
path := serveCmd.Arg(0)
if path == "" {
Expand All @@ -54,6 +50,8 @@ func main() {
logger.Printf("Serving %s on HTTP port: %s with Access-Control-Allow-Origin: %s\n", path, *port, *cors)
logger.Fatal(http.ListenAndServe(":"+*port, nil))
case "subpyramid":
subpyramidCmd := flag.NewFlagSet("subpyramid", flag.ExitOnError)
cpuProfile := subpyramidCmd.Bool("profile", false, "profiling output")
subpyramidCmd.Parse(os.Args[2:])
path := subpyramidCmd.Arg(0)
output := subpyramidCmd.Arg(1)
Expand Down Expand Up @@ -83,7 +81,7 @@ func main() {
output := convertCmd.Arg(1)
pmtiles.Convert(logger, path, output)
case "upload":
pmtiles.Upload(logger, os.Args)
pmtiles.Upload(logger, os.Args[2:])
case "validate":
// pmtiles.Validate()
default:
Expand Down
20 changes: 16 additions & 4 deletions pmtiles/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pmtiles

import (
"context"
"flag"
"github.com/schollz/progressbar/v3"
"gocloud.dev/blob"
"io"
Expand All @@ -10,8 +11,19 @@ import (
)

func Upload(logger *log.Logger, args []string) {
file := args[2]
bucketURL := args[3]
cmd := flag.NewFlagSet("upload", flag.ExitOnError)
buffer_size := cmd.Int("buffer-size", 8, "Upload chunk size in megabytes")
max_concurrency := cmd.Int("max-concurrency", 5, "Number of upload threads")

cmd.Parse(args)
file := cmd.Arg(0)
bucketURL := cmd.Arg(1)

if file == "" || bucketURL == "" {
logger.Println("USAGE: upload [-buffer-size B] [-max-concurrency M] INPUT s3://BUCKET?region=region")
os.Exit(1)
}

logger.Println(file, bucketURL)
ctx := context.Background()
b, err := blob.OpenBucket(ctx, bucketURL)
Expand All @@ -35,8 +47,8 @@ func Upload(logger *log.Logger, args []string) {
buffer := make([]byte, 16*1024*1024)

opts := &blob.WriterOptions{
BufferSize: 256 * 1000 * 1000,
MaxConcurrency: 2,
BufferSize: *buffer_size * 1000 * 1000,
MaxConcurrency: *max_concurrency,
}

w, err := b.NewWriter(ctx, file, opts)
Expand Down

0 comments on commit 52d1129

Please sign in to comment.