diff --git a/cmd/pull.go b/cmd/pull.go index 0a26aa0..9d6bb21 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -22,8 +22,12 @@ var pullCmd = &cobra.Command{ if err != nil { return err } + host, err := cmd.Flags().GetString("host") + if err != nil { + return err + } - port, err := api.ReceiveTarGzFromServer(id) + port, err := api.ReceiveTarGzFromServer(host, id) if err != nil { return err } @@ -48,6 +52,7 @@ var pullCmd = &cobra.Command{ func init() { rootCmd.AddCommand(pullCmd) pullCmd.Flags().StringP("id", "i", "", "ketos docker image id") + pushCmd.Flags().StringP("host", "h", "", "URL of the server to use") // Here you will define your flags and configuration settings. diff --git a/cmd/push.go b/cmd/push.go index fbacc3a..71b8099 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -74,7 +74,7 @@ func init() { pushCmd.Flags().StringP("directory", "d", "", "Directory path to create docker image") pushCmd.Flags().StringP("language", "l", "", "Language type to create docker image") pushCmd.Flags().StringP("filename", "f", "", "Dockerfile name to create docker image") - pushCmd.Flags().StringP("host", "f", "", "URL of the server to use") + pushCmd.Flags().StringP("host", "h", "", "URL of the server to use") pushCmd.Flags().BoolP("dockerfile", "D", false, "Dockerfile or buildpacks") pushCmd.Flags().StringSliceP("publish", "p", []string{}, "Publish a container's port(s) to the host") pushCmd.Flags().StringSliceP("env", "e", []string{}, "Set environment variable(s)") diff --git a/internal/api/receive_file.go b/internal/api/receive_file.go index 12425bf..f0f4c47 100644 --- a/internal/api/receive_file.go +++ b/internal/api/receive_file.go @@ -10,11 +10,11 @@ import ( ) type Response struct { - Port string `json:"port"` - ID string `json:"id"` + Port string `json:"port"` + ID string `json:"id"` } -func GetServerInfo(id string) (string,error) { +func GetServerInfo(id string) (string, error) { fullURL := fmt.Sprintf("%s/info/%s", BackendURL, id) response, err := http.Get(fullURL) if err != nil { @@ -33,19 +33,22 @@ func GetServerInfo(id string) (string,error) { if err != nil { return "", err } - fmt.Printf("%s/info/%s\n", FrontURL, id) + fmt.Printf("%s/info/%s\n", FrontURL, id) return resp.Port, nil } -func ReceiveTarGzFromServer(id string) (string, error) { - fullURL := fmt.Sprintf("%s/%s", BackendURL, id) +func ReceiveTarGzFromServer(host string, id string) (string, error) { + if host == "" { + host = BackendURL + } + fullURL := fmt.Sprintf("%s/%s", host, id) response, err := http.Get(fullURL) if err != nil { return "", err } defer response.Body.Close() - infoURL := fmt.Sprintf("%s/info/%s", BackendURL, id) + infoURL := fmt.Sprintf("%s/info/%s", host, id) infoResponse, err := http.Get(infoURL) if err != nil { return "", err