Skip to content

Commit

Permalink
fix(cli): check if file exists before uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmerrill committed Aug 12, 2023
1 parent b48fef3 commit 8783ed0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions cli/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ var UploadCommand = cli.Command{
},
},
Action: func(cCtx *cli.Context) error {
user, err := supabase.Auth.User(ctx, settings.AccessToken)

if err != nil {
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
}

if user == nil {
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
}

args := UploadOptions{
File: cCtx.Args().First(),
Editor: cCtx.String("editor"),
Expand All @@ -104,6 +114,13 @@ var UploadCommand = cli.Command{
Quiet: cCtx.Bool("quiet"),
}

if args.File != "" {
// Check if the file exists
if _, err := os.Stat(args.File); os.IsNotExist(err) {
return cli.Exit("The file you specified does not exist.", 1)
}
}

if args.Language == "" {
// Try to get the language from the file extension
if args.File != "" {
Expand Down Expand Up @@ -229,6 +246,10 @@ func UploadFile(path string, opts UploadOptions) {
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
}

if user == nil {
cli.Exit("You don't seem to be signed in. Try running `openbin login` to sign in.", 1)
}

supabase.DB.AddHeader("Authorization", fmt.Sprintf("Bearer %s", settings.AccessToken))

err = supabase.DB.From("pastes").Insert(map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/urfave/cli/v2"
)

const VERSION = "1.0.7"
const VERSION = "1.0.8"

type GitHubResponse struct {
TagName string `json:"tag_name"`
Expand Down

0 comments on commit 8783ed0

Please sign in to comment.