Skip to content

Commit 8783ed0

Browse files
committed
fix(cli): check if file exists before uploading
1 parent b48fef3 commit 8783ed0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cli/cmd/upload.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ var UploadCommand = cli.Command{
9191
},
9292
},
9393
Action: func(cCtx *cli.Context) error {
94+
user, err := supabase.Auth.User(ctx, settings.AccessToken)
95+
96+
if err != nil {
97+
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
98+
}
99+
100+
if user == nil {
101+
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
102+
}
103+
94104
args := UploadOptions{
95105
File: cCtx.Args().First(),
96106
Editor: cCtx.String("editor"),
@@ -104,6 +114,13 @@ var UploadCommand = cli.Command{
104114
Quiet: cCtx.Bool("quiet"),
105115
}
106116

117+
if args.File != "" {
118+
// Check if the file exists
119+
if _, err := os.Stat(args.File); os.IsNotExist(err) {
120+
return cli.Exit("The file you specified does not exist.", 1)
121+
}
122+
}
123+
107124
if args.Language == "" {
108125
// Try to get the language from the file extension
109126
if args.File != "" {
@@ -229,6 +246,10 @@ func UploadFile(path string, opts UploadOptions) {
229246
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
230247
}
231248

249+
if user == nil {
250+
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
251+
}
252+
232253
supabase.DB.AddHeader("Authorization", fmt.Sprintf("Bearer %s", settings.AccessToken))
233254

234255
err = supabase.DB.From("pastes").Insert(map[string]interface{}{

cli/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/urfave/cli/v2"
1414
)
1515

16-
const VERSION = "1.0.7"
16+
const VERSION = "1.0.8"
1717

1818
type GitHubResponse struct {
1919
TagName string `json:"tag_name"`

0 commit comments

Comments
 (0)