Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
add progress bar for uploading file (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosan authored May 24, 2022
1 parent 9be9210 commit d47a536
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions cmd/enterpriseCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,18 @@ func newEnterpriseClusterCustomClassesUploadCmd() *cobra.Command {
os.Exit(1)
}
defer file.Close()

stat, err := file.Stat()
if err != nil {
color.Red(err.Error())
os.Exit(1)
}
reader := progressbar.NewReader(file, progressbar.DefaultBytes(stat.Size(), "uploading "+file.Name()))
client := internal.NewClient()
artifact := internal.Validate(client.EnterpriseCluster.UploadArtifact(context.Background(),
&models.UploadArtifactInput{
ClusterId: clusterId,
FileName: filepath.Base(file.Name()),
Content: file,
Content: &reader,
})).(*models.UploadedArtifact)

header := table.Row{"Id", "File Name", "Status"}
Expand Down
8 changes: 7 additions & 1 deletion cmd/serverless_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,18 @@ func newServerlessClusterCustomClassesUploadCmd() *cobra.Command {
}
defer file.Close()

stat, err := file.Stat()
if err != nil {
color.Red(err.Error())
os.Exit(1)
}
reader := progressbar.NewReader(file, progressbar.DefaultBytes(stat.Size(), "uploading "+file.Name()))
client := internal.NewClient()
artifact := internal.Validate(client.ServerlessCluster.UploadArtifact(context.Background(),
&models.UploadArtifactInput{
ClusterId: clusterId,
FileName: filepath.Base(file.Name()),
Content: file,
Content: &reader,
})).(*models.UploadedArtifact)

header := table.Row{"Id", "File Name", "Status"}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.3.0
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.3
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.4
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/schollz/progressbar/v3 v3.8.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.3 h1:DTJ5xn1pInVHVy3tOlnqBTO+jwZG/SFuTce9A47mgn4=
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.3/go.mod h1:3Iane/AnU7k1x2+t4C9BrE6CTGU/T/3i79DVFLbJLkg=
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.4 h1:Mea+8KJevSZPJtcTyFvggJoAVhQHNRoha/P3ayoo6S0=
github.com/hazelcast/hazelcast-cloud-sdk-go v1.3.4/go.mod h1:3Iane/AnU7k1x2+t4C9BrE6CTGU/T/3i79DVFLbJLkg=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand Down

0 comments on commit d47a536

Please sign in to comment.