Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/MakeNowJust/heredoc"
Expand All @@ -13,6 +12,10 @@ type getCmdFlags struct {
app string
}

type serverResponse struct {
AppUrl string `json:"app_url"`
}

func init() {
getCmdFlags := getCmdFlags{}
getCmd := &cobra.Command{
Expand All @@ -25,27 +28,25 @@ func init() {
$ gh runtime get --app my-app
# => Retrieves details of the app named 'my-app'
`),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
if getCmdFlags.app == "" {
fmt.Println("Error: --app flag is required")
return
return fmt.Errorf("--app flag is required")
}

getUrl := fmt.Sprintf("runtime/%s/deployment", getCmdFlags.app)
client, err := api.DefaultRESTClient()
if err != nil {
fmt.Println(err)
return
return fmt.Errorf("failed creating REST client: %v", err)
}

response := json.RawMessage{}
response := serverResponse{}
err = client.Get(getUrl, &response)
if err != nil {
fmt.Printf("Error retrieving app details: %v\n", err)
return
return fmt.Errorf("retrieving app details: %v", err)
}

fmt.Printf("App Details: %s\n", response)
fmt.Printf("%s\n", response.AppUrl)
return nil
},
}

Expand Down
16 changes: 14 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@ var rootCmd = &cobra.Command{
},
}

func Execute() {
type exitCode int

const (
exitOK exitCode = 0
exitError exitCode = 1
exitCancel exitCode = 2
exitAuth exitCode = 4
exitPending exitCode = 8
)

func Execute() exitCode {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
return exitError
}

return exitOK
}
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"os"

"github.com/github/gh-runtime-cli/cmd"
)

func main() {
cmd.Execute()
code := cmd.Execute()
os.Exit(int(code))
}