Skip to content

Commit

Permalink
added a little interface when you want to upload stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjoerd Riemersma committed May 3, 2021
1 parent 0c76e88 commit 1588660
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
55 changes: 41 additions & 14 deletions cmd/afosto/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/afosto/cli/pkg/auth"
"github.com/afosto/cli/pkg/client"
"github.com/afosto/cli/pkg/logging"
"github.com/gen2brain/dlgs"
"github.com/spf13/cobra"
"io"
"log"
Expand All @@ -20,8 +21,6 @@ var _ io.Reader = (*os.File)(nil)

func GetCommands() []*cobra.Command {

dir, _ := os.Getwd()

renderCmd := &cobra.Command{
Use: "upload",
Short: "Upload template",
Expand All @@ -31,36 +30,64 @@ func GetCommands() []*cobra.Command {
upload(cmd, args)
}}

renderCmd.Flags().StringP("source", "s", dir, "")
renderCmd.Flags().StringP("destination", "d", "/uploads/", "")
renderCmd.Flags().StringP("source", "s", "", "")
renderCmd.Flags().StringP("destination", "d", "", "")

return []*cobra.Command{renderCmd}
}

func upload(cmd *cobra.Command, args []string) {
user := auth.GetUser()
if user == nil {
user = auth.GetImplicitUser([]string{
"openid",
"email",
"profile",
"cnt:files:read",
"cnt:files:write",
})
}
ctx := context.WithValue(context.Background(), client.Jwt, user.GetAccessToken())

source, err := cmd.Flags().GetString("source")

if err != nil {
log.Fatal(err)
}

if source == "" {
selectedSource, isSuccessfull, err := dlgs.File("Select directory to upload", "", true)

if err != nil {
log.Fatal(err)
}

if !isSuccessfull {
log.Fatal("failed to select a directory")
}

source = selectedSource
}

destination, err := cmd.Flags().GetString("destination")

if err != nil {
log.Fatal(err)
}

user := auth.GetUser()
if user == nil {
user = auth.GetImplicitUser([]string{
"openid",
"email",
"profile",
"cnt:files:read",
"cnt:files:write",
})
if destination == "" {
enteredDestination, isSuccessfull, err := dlgs.Entry("enter the path to upload", "enter the directory to upload to", "/uploads/")

if err != nil {
log.Fatal(err)
}

if !isSuccessfull {
log.Fatal("failed to select a directory")
}

destination = enteredDestination
}
ctx := context.WithValue(context.Background(), client.Jwt, user.GetAccessToken())

fileClient := client.NewFileClient()
queue := make(chan string, 25)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/dghubble/sling v1.3.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/flosch/pongo2/v4 v4.0.2
github.com/gen2brain/dlgs v0.0.0-20210406143744-f512297a108e
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/leekchan/accounting v1.0.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/flosch/pongo2/v4 v4.0.2 h1:gv+5Pe3vaSVmiJvh/BZa82b7/00YUGm0PIyVVLop0Hw=
github.com/flosch/pongo2/v4 v4.0.2/go.mod h1:B5ObFANs/36VwxxlgKpdchIJHMvHB562PW+BWPhwZD8=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gen2brain/dlgs v0.0.0-20210406143744-f512297a108e h1:gzStW3RtMEyRE8N/o7fqppX2YVmeyDKmjGHDlg2p8cM=
github.com/gen2brain/dlgs v0.0.0-20210406143744-f512297a108e/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
Expand Down Expand Up @@ -75,6 +77,7 @@ github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
Expand Down

0 comments on commit 1588660

Please sign in to comment.