brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [02/19] brooklyn-client git commit: Add catalog list
Date Tue, 25 Oct 2016 19:10:56 GMT
Add catalog list


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/16eff1b0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/16eff1b0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/16eff1b0

Branch: refs/heads/master
Commit: 16eff1b0b2290eea1d3d1bd1b8907637197bc974
Parents: 7db8e15
Author: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Authored: Wed Oct 12 14:07:59 2016 +0100
Committer: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Committed: Wed Oct 12 14:07:59 2016 +0100

----------------------------------------------------------------------
 cli/app/app.go                 |  3 +-
 cli/command_factory/factory.go |  2 +-
 cli/commands/catalog-list.go   | 63 +++++++++++++++++++++++++++++++++++++
 cli/commands/catalog.go        | 42 +++++++++++++++++--------
 4 files changed, 94 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/16eff1b0/cli/app/app.go
----------------------------------------------------------------------
diff --git a/cli/app/app.go b/cli/app/app.go
index 4fb39a2..ad96fa3 100644
--- a/cli/app/app.go
+++ b/cli/app/app.go
@@ -19,7 +19,6 @@
 package app
 
 import (
-	"fmt"
 	"github.com/apache/brooklyn-client/cli/command_metadata"
 	"github.com/apache/brooklyn-client/cli/command_runner"
 	"github.com/apache/brooklyn-client/cli/error_handler"
@@ -111,7 +110,7 @@ func subCommandAction(command string, operand string, runner command_runner.Runn
 	return func(context *cli.Context) {
 		err := runner.RunSubCmdByName(command, operand, context)
 		if err != nil {
-			fmt.Fprintln(os.Stderr, err)
+			error_handler.ErrorExit(err)
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/16eff1b0/cli/command_factory/factory.go
----------------------------------------------------------------------
diff --git a/cli/command_factory/factory.go b/cli/command_factory/factory.go
index ae1634d..399014f 100644
--- a/cli/command_factory/factory.go
+++ b/cli/command_factory/factory.go
@@ -55,7 +55,7 @@ func NewFactory(network *net.Network, config *io.Config) (factory concreteFactor
 	factory.simpleCommand(commands.NewAddChildren(network))
 	factory.simpleCommand(commands.NewApplication(network))
 	//factory.simpleCommand(commands.NewApplications(network))
-	factory.simpleCommand(commands.NewCatalog(network))
+	factory.superCommand(commands.NewCatalog(network))
 	factory.simpleCommand(commands.NewConfig(network))
 	factory.simpleCommand(commands.NewDeploy(network))
 	factory.simpleCommand(commands.NewDelete(network))

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/16eff1b0/cli/commands/catalog-list.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-list.go b/cli/commands/catalog-list.go
new file mode 100644
index 0000000..bb6efe3
--- /dev/null
+++ b/cli/commands/catalog-list.go
@@ -0,0 +1,63 @@
+/*
+ * 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/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/apache/brooklyn-client/cli/terminal"
+	"github.com/urfave/cli"
+)
+
+type CatalogList struct {
+	network *net.Network
+}
+
+func NewCatalogList(network *net.Network) (cmd *CatalogList) {
+	cmd = new(CatalogList)
+	cmd.network = network
+	return
+}
+
+func (cmd *CatalogList) Metadata() command_metadata.CommandMetadata {
+	return command_metadata.CommandMetadata{
+		Name:        "list",
+		Description: "* List the available catalog applications",
+		Usage:       "BROOKLYN_NAME catalog list",
+		Flags:       []cli.Flag{},
+	}
+}
+
+func (cmd *CatalogList) Run(scope scope.Scope, c *cli.Context) {
+	if err := net.VerifyLoginURL(cmd.network); err != nil {
+		error_handler.ErrorExit(err)
+	}
+	catalog, err := catalog.Catalog(cmd.network)
+	if nil != err {
+		error_handler.ErrorExit(err)
+	}
+	table := terminal.NewTable([]string{"Id", "Name", "Description"})
+	for _, app := range catalog {
+		table.Add(app.Id, app.Name, app.Description)
+	}
+	table.Print()
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/16eff1b0/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index eab08b8..6cfc324 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -19,31 +19,54 @@
 package commands
 
 import (
-	"github.com/apache/brooklyn-client/cli/api/catalog"
+	"github.com/apache/brooklyn-client/cli/command"
 	"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/apache/brooklyn-client/cli/terminal"
 	"github.com/urfave/cli"
+	"strings"
+	"fmt"
 )
 
 type Catalog struct {
 	network *net.Network
+	catalogCommands map[string]command.Command
 }
 
 func NewCatalog(network *net.Network) (cmd *Catalog) {
 	cmd = new(Catalog)
 	cmd.network = network
+	cmd.catalogCommands = map[string]command.Command {
+		ListCatalogCommand: NewCatalogList(cmd.network),
+	}
 	return
 }
 
+const ListCatalogCommand = "list"
+
+var catalogCommands = []string{
+	ListCatalogCommand,
+}
+var catalogCommandsUsage = strings.Join(catalogCommands, " | ")
+
+func (cmd *Catalog) SubCommandNames() []string {
+	return catalogCommands
+}
+
+func (cmd *Catalog) SubCommand(name string) command.Command {
+	return cmd.catalogCommands[name]
+}
+
 func (cmd *Catalog) Metadata() command_metadata.CommandMetadata {
 	return command_metadata.CommandMetadata{
 		Name:        "catalog",
-		Description: "* List the available catalog applications",
-		Usage:       "BROOKLYN_NAME catalog",
+		Description: "Catalog operations",
+		Usage:       "BROOKLYN_NAME catalog (" + catalogCommandsUsage + ")",
 		Flags:       []cli.Flag{},
+		Operands:    []command_metadata.CommandMetadata{
+			cmd.SubCommand(ListCatalogCommand).Metadata(),
+		},
 	}
 }
 
@@ -51,13 +74,6 @@ func (cmd *Catalog) Run(scope scope.Scope, c *cli.Context) {
 	if err := net.VerifyLoginURL(cmd.network); err != nil {
 		error_handler.ErrorExit(err)
 	}
-	catalog, err := catalog.Catalog(cmd.network)
-	if nil != err {
-		error_handler.ErrorExit(err)
-	}
-	table := terminal.NewTable([]string{"Id", "Name", "Description"})
-	for _, app := range catalog {
-		table.Add(app.Id, app.Name, app.Description)
-	}
-	table.Print()
+	fmt.Printf("Unrecognised instruction, please use one of (%s)\n", catalogCommandsUsage)
+
 }


Mime
View raw message