Skip to content

Commit

Permalink
Cleanup: open command
Browse files Browse the repository at this point in the history
  • Loading branch information
wendorf committed Oct 15, 2021
1 parent 9df31cf commit 854f9b5
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions cmd/open.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"

"github.com/renderinc/cli/pkg/http"
"github.com/renderinc/cli/pkg/table"
"github.com/spf13/cobra"
"github.com/skratchdot/open-golang/open"
)
Expand All @@ -26,28 +23,14 @@ var openCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
serviceId := args[0]
cds := customDomains(serviceId)
var url string
if len(cds) != 0 {
if err := open.Run(fmt.Sprintf("https://%s", cds[0].Name)); err != nil {
panic(err)
}
return
url = fmt.Sprintf("https://%s", cds[0].Name)
} else {
svc := service(serviceId)
url = fmt.Sprintf("https://%s.onrender.com", svc.Slug)
}

svc := service(serviceId)
if err := open.Run(fmt.Sprintf("https://%s.onrender.com", svc.Slug)); err != nil {
panic(err)
}
jsonString, err := http.Request(fmt.Sprintf("services/%s", serviceId))
if err != nil {
panic(err)
}

var service Service
if err := json.Unmarshal(jsonString, &service); err != nil {
panic(err)
}

if err := table.Print([]string{"Id", "Name", "Type", "State"}, []Service{service}); err != nil {
if err := open.Run(url); err != nil {
panic(err)
}
},
Expand Down

0 comments on commit 854f9b5

Please sign in to comment.