You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/25 19:11:04 UTC
[10/19] brooklyn-client git commit: Do arguments to `delete` as such,
rather than as flags.
Do arguments to `delete` as such, rather than as flags.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/baa28010
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/baa28010
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/baa28010
Branch: refs/heads/master
Commit: baa28010b55fd4c19d59b781e22178fc08885afa
Parents: 3c6d1e5
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Mon Oct 24 14:32:31 2016 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Oct 24 14:32:31 2016 +0100
----------------------------------------------------------------------
cli/commands/catalog-delete.go | 110 +++++++++++++++++++++++
cli/commands/catalog-list.go | 12 +--
cli/commands/catalog.go | 5 +-
cli/commands/delete-catalog-application.go | 115 ------------------------
4 files changed, 118 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/baa28010/cli/commands/catalog-delete.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-delete.go b/cli/commands/catalog-delete.go
new file mode 100644
index 0000000..443f550
--- /dev/null
+++ b/cli/commands/catalog-delete.go
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 commands
+
+import (
+ "github.com/apache/brooklyn-client/cli/net"
+ "github.com/apache/brooklyn-client/cli/command_metadata"
+ "github.com/urfave/cli"
+ "github.com/apache/brooklyn-client/cli/scope"
+ "github.com/apache/brooklyn-client/cli/error_handler"
+ "strings"
+ "github.com/apache/brooklyn-client/cli/api/catalog"
+ "errors"
+)
+
+type DeleteCatalogItem struct {
+ network *net.Network
+}
+
+func NewDeleteCatalogItem(network *net.Network) (cmd *DeleteCatalogItem) {
+ cmd = new(DeleteCatalogItem)
+ cmd.network = network
+ return
+}
+
+func (cmd *DeleteCatalogItem) Metadata() command_metadata.CommandMetadata {
+ return command_metadata.CommandMetadata{
+ Name: "delete",
+ Description: "delete the given catalog item",
+ Usage: "BROOKLYN_NAME catalog " + deleteCommandName +
+ " TYPE [ITEM_ID:VERSION] (where TYPE is one of applications, locations, entities, policies, may be abbreviated)",
+ }
+}
+
+const deleteCommandName = "delete"
+
+
+func (cmd *DeleteCatalogItem) Run(scope scope.Scope, c *cli.Context) {
+ if err := net.VerifyLoginURL(cmd.network); err != nil {
+ error_handler.ErrorExit(err)
+ }
+ args := c.Args()
+ if len(args) != 2 {
+ error_handler.ErrorExit("command requires arguments TYPE ITEM_ID:VERSION")
+ }
+ itemVersion := strings.Split(args.Get(1), ":")
+ if len(itemVersion) != 2 {
+ error_handler.ErrorExit("command requires arguments TYPE ITEM_ID:VERSION")
+ }
+ itemId := itemVersion[0]
+ version := itemVersion[1]
+ err := cmd.deleteItem(c, itemId, version)
+ if nil != err {
+ error_handler.ErrorExit(err)
+ }
+}
+
+func (cmd *DeleteCatalogItem) deleteItem(c *cli.Context, itemId string, version string) (error){
+ catalogType, err := GetCatalogType(c)
+ if err != nil {
+ return err
+ }
+ switch catalogType {
+ case ApplicationsItemType:
+ return cmd.deleteApplication(c, itemId, version)
+ case EntitiesItemType:
+ return cmd.deleteEntity(c, itemId, version)
+ case LocationsItemType:
+ return cmd.deleteLocation(c, itemId, version)
+ case PoliciesItemType:
+ return cmd.deletePolicy(c, itemId, version)
+ }
+ return errors.New("Unknown type " + c.Args().First())
+}
+
+func (cmd *DeleteCatalogItem) deleteApplication(c *cli.Context, itemId string, version string) (error){
+ _, err := catalog.DeleteApplicationWithVersion(cmd.network, itemId, version)
+ return err
+}
+
+func (cmd *DeleteCatalogItem) deleteEntity(c *cli.Context, itemId string, version string) (error){
+ _, err := catalog.DeleteEntityWithVersion(cmd.network, itemId, version)
+ return err
+}
+
+func (cmd *DeleteCatalogItem) deletePolicy(c *cli.Context, itemId string, version string) (error){
+ _, err := catalog.DeletePolicyWithVersion(cmd.network, itemId, version)
+ return err
+}
+
+func (cmd *DeleteCatalogItem) deleteLocation(c *cli.Context, itemId string, version string) (error){
+ _, err := catalog.DeleteLocationWithVersion(cmd.network, itemId, version)
+ return err
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/baa28010/cli/commands/catalog-list.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-list.go b/cli/commands/catalog-list.go
index 7814b48..bc22c2c 100644
--- a/cli/commands/catalog-list.go
+++ b/cli/commands/catalog-list.go
@@ -40,13 +40,13 @@ func NewCatalogList(network *net.Network) (cmd *CatalogList) {
return
}
-const commandName = "list"
+const listCommandName = "list"
func (cmd *CatalogList) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
- Name: commandName,
+ Name: listCommandName,
Description: "* List the available catalog applications",
- Usage: "BROOKLYN_NAME catalog " + commandName,
+ Usage: "BROOKLYN_NAME catalog " + listCommandName + " " + catalogItemTypesUsage + " (may be abbreviated)",
}
}
@@ -66,8 +66,10 @@ func (cmd *CatalogList) Run(scope scope.Scope, c *cli.Context) {
}
func (cmd *CatalogList) list(c *cli.Context) ([]models.IdentityDetails, error) {
-
- catalogType, err := GetCatalogType(c, commandName)
+ if len(c.Args()) != 1 {
+ return nil, errors.New(c.App.Name + " " + listCommandName + catalogItemTypesUsage + " (may be abbreviated)")
+ }
+ catalogType, err := GetCatalogType(c)
if err != nil {
return nil, err
}
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/baa28010/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index f0cee15..86073a6 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -67,10 +67,7 @@ const (
)
const catalogItemTypesUsage = " ( applications | entities | locations | policies )"
-func GetCatalogType(c *cli.Context, commandName string) (CatalogItemType, error) {
- if len(c.Args()) != 1 {
- return Unknown, errors.New(c.App.Name + " " + commandName + catalogItemTypesUsage)
- }
+func GetCatalogType(c *cli.Context) (CatalogItemType, error) {
commandType := c.Args().First()
if strings.HasPrefix("entities", commandType) {
return EntitiesItemType, nil
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/baa28010/cli/commands/delete-catalog-application.go
----------------------------------------------------------------------
diff --git a/cli/commands/delete-catalog-application.go b/cli/commands/delete-catalog-application.go
deleted file mode 100644
index 888184c..0000000
--- a/cli/commands/delete-catalog-application.go
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 commands
-
-import (
- "github.com/apache/brooklyn-client/cli/net"
- "github.com/apache/brooklyn-client/cli/command_metadata"
- "github.com/urfave/cli"
- "github.com/apache/brooklyn-client/cli/scope"
- "github.com/apache/brooklyn-client/cli/error_handler"
- "strings"
- "github.com/apache/brooklyn-client/cli/api/catalog"
-)
-
-type DeleteCatalogItem struct {
- network *net.Network
-}
-
-func NewDeleteCatalogItem(network *net.Network) (cmd *DeleteCatalogItem) {
- cmd = new(DeleteCatalogItem)
- cmd.network = network
- return
-}
-
-func (cmd *DeleteCatalogItem) Metadata() command_metadata.CommandMetadata {
- return command_metadata.CommandMetadata{
- Name: "delete",
- Description: "delete the given catalog item",
- Usage: "BROOKLYN_NAME catalog delete [ITEM_ID:VERSION]",
- Flags: []cli.Flag{
- cli.BoolFlag{
- Name: "applications, a",
- Usage: "delete application (default)",
- },
- cli.BoolFlag{
- Name: "entities, e",
- Usage: "delete entity",
- },
- cli.BoolFlag{
- Name: "locations, l",
- Usage: "delete location",
- },
- cli.BoolFlag{
- Name: "policies, p",
- Usage: "delete policy",
- },
- },
- }
-}
-
-func (cmd *DeleteCatalogItem) Run(scope scope.Scope, c *cli.Context) {
- if err := net.VerifyLoginURL(cmd.network); err != nil {
- error_handler.ErrorExit(err)
- }
- if len(c.Args()) != 1 {
- error_handler.ErrorExit("command requires single argument ITEM_ID:VERSION")
- }
- itemVersion := strings.Split(c.Args().First(), ":")
- if len(itemVersion) != 2 {
- error_handler.ErrorExit("command requires single argument ITEM_ID:VERSION")
- }
- itemId := itemVersion[0]
- version := itemVersion[1]
- err := cmd.deleteItem(c, itemId, version)
- if nil != err {
- error_handler.ErrorExit(err)
- }
-}
-
-func (cmd *DeleteCatalogItem) deleteItem(c *cli.Context, itemId string, version string) (error){
- if c.IsSet("entities") {
- return cmd.deleteEntity(c, itemId, version)
- } else if c.IsSet("locations") {
- return cmd.deleteLocation(c, itemId, version)
- } else if c.IsSet("policies") {
- return cmd.deletePolicy(c, itemId, version)
- }
- return cmd.deleteApplication(c, itemId, version)
-}
-
-func (cmd *DeleteCatalogItem) deleteApplication(c *cli.Context, itemId string, version string) (error){
- _, err := catalog.DeleteApplicationWithVersion(cmd.network, itemId, version)
- return err
-}
-
-func (cmd *DeleteCatalogItem) deleteEntity(c *cli.Context, itemId string, version string) (error){
- _, err := catalog.DeleteEntityWithVersion(cmd.network, itemId, version)
- return err
-}
-
-func (cmd *DeleteCatalogItem) deletePolicy(c *cli.Context, itemId string, version string) (error){
- _, err := catalog.DeletePolicyWithVersion(cmd.network, itemId, version)
- return err
-}
-
-func (cmd *DeleteCatalogItem) deleteLocation(c *cli.Context, itemId string, version string) (error){
- _, err := catalog.DeleteLocationWithVersion(cmd.network, itemId, version)
- return err
-}
\ No newline at end of file