|
| 1 | +// Copyright © 2018 Codefresh.Inc |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package cmd |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + |
| 20 | + "github.com/codefresh-io/go-sdk/pkg/codefresh" |
| 21 | + |
| 22 | + "github.com/codefresh-io/go-sdk/pkg/utils" |
| 23 | + "github.com/spf13/cobra" |
| 24 | + "github.com/spf13/viper" |
| 25 | +) |
| 26 | + |
| 27 | +// createRuntimeEnvironmentCmd represents the createRuntimeEnvironment command |
| 28 | +var createRuntimeEnvironmentCmd = &cobra.Command{ |
| 29 | + Use: "runtime-environment", |
| 30 | + Aliases: []string{"re"}, |
| 31 | + Short: "Create runtime environment", |
| 32 | + |
| 33 | + Run: func(cmd *cobra.Command, args []string) { |
| 34 | + client := viper.Get("codefresh") |
| 35 | + codefreshClient := utils.CastToCodefreshOrDie(client) |
| 36 | + cluster := cmd.Flag("cluster").Value.String() |
| 37 | + namespace := cmd.Flag("namespace").Value.String() |
| 38 | + opt := &codefresh.CreateRuntimeOptions{ |
| 39 | + Cluster: cluster, |
| 40 | + Namespace: namespace, |
| 41 | + HasAgent: true, |
| 42 | + } |
| 43 | + re, err := codefreshClient.CreateRuntimeEnvironment(opt) |
| 44 | + if err == nil { |
| 45 | + fmt.Printf("Runtime-Environment %s created\n", re.Name) |
| 46 | + } |
| 47 | + }, |
| 48 | +} |
| 49 | + |
| 50 | +func init() { |
| 51 | + createCmd.AddCommand(createRuntimeEnvironmentCmd) |
| 52 | + createRuntimeEnvironmentCmd.Flags().String("cluster", "", "Set name of the cluster (required)") |
| 53 | + createRuntimeEnvironmentCmd.MarkFlagRequired("cluster") |
| 54 | + createRuntimeEnvironmentCmd.Flags().String("namespace", "", "Set name of the namespace (required)") |
| 55 | + createRuntimeEnvironmentCmd.MarkFlagRequired("namespace") |
| 56 | + createRuntimeEnvironmentCmd.Flags().Bool("has-agent", false, "Set if the runtime environment is managed by Codefresh agent") |
| 57 | +} |
0 commit comments