From b25a96db12db4b3f246cba2c4476f64d0aa118a0 Mon Sep 17 00:00:00 2001 From: stormcat24 Date: Thu, 3 Nov 2016 20:32:08 +0900 Subject: [PATCH] add all apply option for secure --- README.md | 22 ++++++--------------- cmd/cluster.go | 47 -------------------------------------------- cmd/root.go | 1 + cmd/service/apply.go | 1 - cmd/service/init.go | 9 +++++++++ cmd/task/init.go | 12 +++++++++++ 6 files changed, 28 insertions(+), 64 deletions(-) delete mode 100644 cmd/cluster.go diff --git a/README.md b/README.md index ed439a0..f29b2e2 100644 --- a/README.md +++ b/README.md @@ -135,39 +135,29 @@ test-service: Show update plan. ```bash -(path-to-path/test-ecs-formation $ ecs-formation task plan +(path-to-path/test-ecs-formation $ ecs-formation task plan --all +(path-to-path/test-ecs-formation $ ecs-formation task plan -t test_definition ``` Apply all definition. ```bash -(path-to-path/test-ecs-formation $ ecs-formation task apply -``` - -Specify Task Definition. - -```bash +(path-to-path/test-ecs-formation $ ecs-formation task apply --all (path-to-path/test-ecs-formation $ ecs-formation task apply -t test_definition ``` #### Manage Services on Cluster -Show update plan. +Show update plan. Required cluster. ```bash -(path-to-path/test-ecs-formation $ ecs-formation service plan +(path-to-path/test-ecs-formation $ ecs-formation service plan -c test-cluster --all ``` Apply all services. ```bash -(path-to-path/test-ecs-formation $ ecs-formation service apply -``` - -Specify cluster. - -```bash -(path-to-path/test-ecs-formation $ ecs-formation service apply -c test-cluster +(path-to-path/test-ecs-formation $ ecs-formation service apply -c test-cluster --all ``` Specify cluster and service. diff --git a/cmd/cluster.go b/cmd/cluster.go deleted file mode 100644 index 5e1ed08..0000000 --- a/cmd/cluster.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2016 NAME HERE -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -// clusterCmd represents the cluster command -var clusterCmd = &cobra.Command{ - Use: "cluster", - Short: "Manage Amazon ECS Cluster", - RunE: func(cmd *cobra.Command, args []string) error { - // TODO: Work your own magic here - fmt.Println("cluster called") - return nil - }, -} - -func init() { - RootCmd.AddCommand(clusterCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // clusterCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // clusterCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") - -} diff --git a/cmd/root.go b/cmd/root.go index 4ce4206..57a5e93 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -64,6 +64,7 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + RootCmd.PersistentFlags().BoolP("all", "a", false, "Target all resources") RootCmd.AddCommand(task.TaskCmd, service.ServiceCmd, bluegreen.BlueGreenCmd) } diff --git a/cmd/service/apply.go b/cmd/service/apply.go index 77a038b..570b505 100644 --- a/cmd/service/apply.go +++ b/cmd/service/apply.go @@ -9,7 +9,6 @@ var applyCmd = &cobra.Command{ Use: "apply", Short: "Update ecs service on target cluster", RunE: func(cmd *cobra.Command, args []string) error { - srv, err := service.NewClusterService(projectDir, []string{cluster}, serviceName, parameters) if err != nil { return err diff --git a/cmd/service/init.go b/cmd/service/init.go index 4441ce1..5461a9a 100644 --- a/cmd/service/init.go +++ b/cmd/service/init.go @@ -52,6 +52,15 @@ var ServiceCmd = &cobra.Command{ } serviceName = sv + all, err := cmd.Flags().GetBool("all") + if err != nil { + return err + } + + if serviceName == "" && all == false { + return errors.New("should specify '-s service_name' or '-all' option") + } + paramTokens, err := cmd.Flags().GetStringSlice("parameter") if err != nil { return err diff --git a/cmd/task/init.go b/cmd/task/init.go index 8390758..cb22479 100644 --- a/cmd/task/init.go +++ b/cmd/task/init.go @@ -1,6 +1,8 @@ package task import ( + "errors" + "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stormcat24/ecs-formation/client" @@ -37,11 +39,21 @@ var TaskCmd = &cobra.Command{ } taskDefinition = td + all, err := cmd.Flags().GetBool("all") + if err != nil { + return err + } + + if taskDefinition == "" && all == false { + return errors.New("should specify '-t task_definition_name' or '-all' option") + } + paramTokens, err := cmd.Flags().GetStringSlice("parameter") if err != nil { return err } parameters = util.ParseKeyValues(paramTokens) + return nil }, }