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:03 UTC
[09/19] brooklyn-client git commit: Do arguments to `list` as such,
rather than as flags.
Do arguments to `list` as such, rather than as flags.
Retain the add-catalog command for backward compatibility.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/3c6d1e5e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/3c6d1e5e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/3c6d1e5e
Branch: refs/heads/master
Commit: 3c6d1e5e8d444b1390bc866c0f39111b579bfb4d
Parents: c68dbc4
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Mon Oct 24 13:44:32 2016 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Oct 24 13:44:32 2016 +0100
----------------------------------------------------------------------
cli/commands/add-catalog.go | 10 +++----
cli/commands/catalog-add.go | 61 +++++++++++++++++++++++++++++++++++++++
cli/commands/catalog-list.go | 57 ++++++++++++++++--------------------
cli/commands/catalog.go | 31 ++++++++++++++++++--
4 files changed, 119 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/3c6d1e5e/cli/commands/add-catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/add-catalog.go b/cli/commands/add-catalog.go
index 2d736c3..17bb85c 100644
--- a/cli/commands/add-catalog.go
+++ b/cli/commands/add-catalog.go
@@ -40,9 +40,9 @@ func NewAddCatalog(network *net.Network) (cmd *AddCatalog) {
func (cmd *AddCatalog) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
- Name: "add",
- Description: "* Add a new catalog item from the supplied YAML (a file or http URL)",
- Usage: "BROOKLYN_NAME catalog add ( FILEPATH | URL )",
+ Name: "add-catalog",
+ Description: "(deprecated, use catalog add) Add a new catalog item from the supplied YAML (a file or http URL)",
+ Usage: "BROOKLYN_NAME add-catalog ( FILEPATH | URL )",
Flags: []cli.Flag{},
}
}
@@ -55,7 +55,5 @@ func (cmd *AddCatalog) Run(scope scope.Scope, c *cli.Context) {
if nil != err {
error_handler.ErrorExit(err)
}
- for id, _ := range create {
- fmt.Println(id)
- }
+ fmt.Println(create)
}
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/3c6d1e5e/cli/commands/catalog-add.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-add.go b/cli/commands/catalog-add.go
new file mode 100644
index 0000000..0cf6281
--- /dev/null
+++ b/cli/commands/catalog-add.go
@@ -0,0 +1,61 @@
+/*
+ * 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 (
+ "fmt"
+ "github.com/apache/brooklyn-client/cli/api/catalog"
+ "github.com/apache/brooklyn-client/cli/command_metadata"
+ "github.com/apache/brooklyn-client/cli/error_handler"
+ "github.com/apache/brooklyn-client/cli/net"
+ "github.com/apache/brooklyn-client/cli/scope"
+ "github.com/urfave/cli"
+)
+
+type CatalogAdd struct {
+ network *net.Network
+}
+
+func NewCatalogAdd(network *net.Network) (cmd *CatalogAdd) {
+ cmd = new(CatalogAdd)
+ cmd.network = network
+ return
+}
+
+func (cmd *CatalogAdd) Metadata() command_metadata.CommandMetadata {
+ return command_metadata.CommandMetadata{
+ Name: "add",
+ Description: "Add a new catalog item from the supplied YAML (a file or http URL)",
+ Usage: "BROOKLYN_NAME catalog add ( FILEPATH | URL )",
+ Flags: []cli.Flag{},
+ }
+}
+
+func (cmd *CatalogAdd) Run(scope scope.Scope, c *cli.Context) {
+ if err := net.VerifyLoginURL(cmd.network); err != nil {
+ error_handler.ErrorExit(err)
+ }
+ create, err := catalog.AddCatalog(cmd.network, c.Args().First())
+ if nil != err {
+ error_handler.ErrorExit(err)
+ }
+ for id, _ := range create {
+ fmt.Println(id)
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/3c6d1e5e/cli/commands/catalog-list.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-list.go b/cli/commands/catalog-list.go
index 5fa8414..7814b48 100644
--- a/cli/commands/catalog-list.go
+++ b/cli/commands/catalog-list.go
@@ -27,6 +27,7 @@ import (
"github.com/apache/brooklyn-client/cli/terminal"
"github.com/urfave/cli"
"github.com/apache/brooklyn-client/cli/models"
+ "errors"
)
type CatalogList struct {
@@ -39,29 +40,13 @@ func NewCatalogList(network *net.Network) (cmd *CatalogList) {
return
}
+const commandName = "list"
+
func (cmd *CatalogList) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
- Name: "list",
+ Name: commandName,
Description: "* List the available catalog applications",
- Usage: "BROOKLYN_NAME catalog list",
- Flags: []cli.Flag{
- cli.BoolFlag{
- Name: "applications, a",
- Usage: "list applications (default)",
- },
- cli.BoolFlag{
- Name: "entities, e",
- Usage: "list entities",
- },
- cli.BoolFlag{
- Name: "locations, l",
- Usage: "list locations",
- },
- cli.BoolFlag{
- Name: "policies, p",
- Usage: "list policies",
- },
- },
+ Usage: "BROOKLYN_NAME catalog " + commandName,
}
}
@@ -81,18 +66,26 @@ func (cmd *CatalogList) Run(scope scope.Scope, c *cli.Context) {
}
func (cmd *CatalogList) list(c *cli.Context) ([]models.IdentityDetails, error) {
- if c.IsSet("entities") {
- list, err := cmd.listEntities(c)
- return list, err
- } else if c.IsSet("locations") {
- list, err := cmd.listLocations(c)
- return list, err
- } else if c.IsSet("policies") {
- list, err := cmd.listPolicies(c)
- return list, err
+
+ catalogType, err := GetCatalogType(c, commandName)
+ if err != nil {
+ return nil, err
+ }
+ switch catalogType {
+ case ApplicationsItemType:
+ items, err := cmd.listCatalogApplications(c)
+ return items, err
+ case EntitiesItemType:
+ items, err := cmd.listEntities(c)
+ return items, err
+ case LocationsItemType:
+ items, err := cmd.listLocations(c)
+ return items, err
+ case PoliciesItemType:
+ items, err := cmd.listPolicies(c)
+ return items, err
}
- items, err := cmd.listCatalogItems(c)
- return items, err
+ return nil, errors.New("Unrecognised argument")
}
func (cmd *CatalogList) listPolicies(c *cli.Context) ([]models.IdentityDetails, error) {
@@ -131,7 +124,7 @@ func (cmd *CatalogList) listEntities(c *cli.Context) ([]models.IdentityDetails,
return result, nil
}
-func (cmd *CatalogList) listCatalogItems(c *cli.Context) ([]models.IdentityDetails, error) {
+func (cmd *CatalogList) listCatalogApplications(c *cli.Context) ([]models.IdentityDetails, error) {
items, err := catalog.Catalog(cmd.network)
if err != nil {
return nil, err
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/3c6d1e5e/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index 0cc3380..f0cee15 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -27,6 +27,7 @@ import (
"github.com/urfave/cli"
"strings"
"fmt"
+ "errors"
)
type Catalog struct {
@@ -39,7 +40,7 @@ func NewCatalog(network *net.Network) (cmd *Catalog) {
cmd.network = network
cmd.catalogCommands = map[string]command.Command {
ListCatalogCommand: NewCatalogList(cmd.network),
- AddCatalogCommand: NewAddCatalog(cmd.network),
+ AddCatalogCommand: NewCatalogAdd(cmd.network),
DeleteCatalogCommand: NewDeleteCatalogItem(cmd.network),
}
return
@@ -56,6 +57,33 @@ var catalogCommands = []string{
}
var catalogCommandsUsage = strings.Join(catalogCommands, " | ")
+type CatalogItemType int
+const (
+ Unknown = iota
+ ApplicationsItemType
+ EntitiesItemType
+ LocationsItemType
+ PoliciesItemType
+)
+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)
+ }
+ commandType := c.Args().First()
+ if strings.HasPrefix("entities", commandType) {
+ return EntitiesItemType, nil
+ } else if strings.HasPrefix("locations", commandType) {
+ return LocationsItemType, nil
+ } else if strings.HasPrefix("policies", commandType) {
+ return PoliciesItemType, nil
+ } else if strings.HasPrefix("applications", commandType) {
+ return ApplicationsItemType, nil
+ }
+ return Unknown, errors.New("Unknown type: " + commandType)
+}
+
func (cmd *Catalog) SubCommandNames() []string {
return catalogCommands
}
@@ -83,5 +111,4 @@ func (cmd *Catalog) Run(scope scope.Scope, c *cli.Context) {
error_handler.ErrorExit(err)
}
fmt.Printf("'catalog' requires one of (%s)\n", catalogCommandsUsage)
-
}