Skip to content

Commit 187849f

Browse files
committed
Fix variable names
1 parent c1f73d6 commit 187849f

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

cmd/src/snapshot_upload.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import (
1919
"github.com/sourcegraph/src-cli/internal/pgdump"
2020
)
2121

22-
// GCP docs
23-
// https://pkg.go.dev/cloud.google.com/go/storage#section-readme
24-
2522
const srcSnapshotDir = "./src-snapshot"
2623

2724
var srcSnapshotSummaryPath = path.Join(srcSnapshotDir, "summary.json")
@@ -34,7 +31,7 @@ type uploadArgs struct {
3431
filesToUpload []string
3532
}
3633

37-
type uploadClients struct {
34+
type gcsClient struct {
3835
ctx context.Context
3936
out *output.Output
4037
storageClient *storage.Client
@@ -92,8 +89,8 @@ func snapshotUploadHandler(flagSet *flag.FlagSet, bucketName, credentialsPath *s
9289
return err
9390
}
9491

95-
// Create clients
96-
clients, err := createUploadClients(flagSet, uploadArgs.credentialsPath)
92+
// Create client
93+
client, err := createGcsClient(flagSet, uploadArgs.credentialsPath)
9794
if err != nil {
9895
return err
9996
}
@@ -105,11 +102,11 @@ func snapshotUploadHandler(flagSet *flag.FlagSet, bucketName, credentialsPath *s
105102
}
106103

107104
// Upload files to bucket
108-
return uploadFilesToBucket(clients, uploadArgs, openedFiles, progressBars)
105+
return uploadFilesToBucket(client, uploadArgs, openedFiles, progressBars)
109106
}
110107
}
111108

112-
// Validate user inputs
109+
// Validate user inputs, and convert them to an object of type uploadArgs
113110
func validateUploadInputs(bucketName, credentialsPath, fileFilter string, filterSQL bool) (*uploadArgs, error) {
114111
if bucketName == "" {
115112
return nil, errors.New("-bucket required")
@@ -131,7 +128,7 @@ func validateUploadInputs(bucketName, credentialsPath, fileFilter string, filter
131128
}, nil
132129
}
133130

134-
// Parse the --file arg values
131+
// Parse the --file arg values, and return a list of strings of the files to upload
135132
func parseFileFilter(fileFilter string) ([]string, error) {
136133

137134
validFiles := map[string]bool{
@@ -167,18 +164,18 @@ func parseFileFilter(fileFilter string) ([]string, error) {
167164
return filesToUpload, nil
168165
}
169166

170-
func createUploadClients(flagSet *flag.FlagSet, credentialsPath string) (*uploadClients, error) {
167+
func createGcsClient(flagSet *flag.FlagSet, credentialsPath string) (*gcsClient, error) {
171168

172169
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
173170
ctx := context.Background()
171+
// https://pkg.go.dev/cloud.google.com/go/storage#section-readme
174172
client, err := storage.NewClient(ctx, option.WithCredentialsFile(credentialsPath))
175173

176174
if err != nil {
177-
return nil, errors.Wrap(err, "create Cloud Storage client")
175+
return nil, errors.Wrap(err, "create Google Cloud Storage client")
178176
}
179177

180-
// TODO: Does upload client need to be plural?
181-
return &uploadClients{
178+
return &gcsClient{
182179
ctx: ctx,
183180
out: out,
184181
storageClient: client,
@@ -250,12 +247,12 @@ func openFilesAndCreateProgressBars(args *uploadArgs) ([]uploadFile, []output.Pr
250247

251248
// uploadFilesToBucket uploads the prepared files to Google Cloud Storage bucket.
252249
// Uploads are performed in parallel with progress tracking.
253-
func uploadFilesToBucket(clients *uploadClients, args *uploadArgs, openedFiles []uploadFile, progressBars []output.ProgressBar) error {
250+
func uploadFilesToBucket(client *gcsClient, args *uploadArgs, openedFiles []uploadFile, progressBars []output.ProgressBar) error {
254251
// Start uploads with progress tracking
255-
progress := clients.out.Progress(progressBars, nil)
252+
progress := client.out.Progress(progressBars, nil)
256253
progress.WriteLine(output.Emoji(output.EmojiHourglass, "Starting uploads..."))
257-
bucket := clients.storageClient.Bucket(args.bucketName)
258-
uploadPool := pool.New().WithErrors().WithContext(clients.ctx)
254+
bucket := client.storageClient.Bucket(args.bucketName)
255+
uploadPool := pool.New().WithErrors().WithContext(client.ctx)
259256

260257
// Upload each file in parallel
261258
for fileIndex, openedFile := range openedFiles {
@@ -276,11 +273,11 @@ func uploadFilesToBucket(clients *uploadClients, args *uploadArgs, openedFiles [
276273
errs := uploadPool.Wait()
277274
progress.Complete()
278275
if errs != nil {
279-
clients.out.WriteLine(output.Line(output.EmojiFailure, output.StyleFailure, "Some snapshot contents failed to upload."))
276+
client.out.WriteLine(output.Line(output.EmojiFailure, output.StyleFailure, "Some snapshot contents failed to upload."))
280277
return errs
281278
}
282279

283-
clients.out.WriteLine(output.Emoji(output.EmojiSuccess, "Summary contents uploaded!"))
280+
client.out.WriteLine(output.Emoji(output.EmojiSuccess, "Summary contents uploaded!"))
284281
return nil
285282
}
286283

0 commit comments

Comments
 (0)