Skip to content

Commit

Permalink
Resolves hyperledger#271, info command now output information
Browse files Browse the repository at this point in the history
about the stack not container.

Signed-off-by: tobigiwa <[email protected]>
  • Loading branch information
tobigiwa committed Oct 6, 2023
1 parent e7623ee commit afa66c4
Show file tree
Hide file tree
Showing 34 changed files with 740 additions and 94 deletions.
35 changes: 26 additions & 9 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"context"
"fmt"
"strings"

"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/log"
Expand All @@ -30,7 +31,7 @@ var infoCmd = &cobra.Command{
Use: "info <stack_name>",
Short: "Get info about a stack",
Long: `Get info about a stack such as each container name
and image version.`,
and image version. If non is given, it run the "info" command for all stack on the local machine.`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := log.WithVerbosity(context.Background(), verbose)
ctx = context.WithValue(ctx, docker.CtxIsLogCmdKey{}, true)
Expand All @@ -42,17 +43,33 @@ var infoCmd = &cobra.Command{
}
ctx = context.WithValue(ctx, docker.CtxComposeVersionKey{}, version)

stackManager := stacks.NewStackManager(ctx)
if len(args) == 0 {
return fmt.Errorf("no stack specified")
allStacks, err := stacks.ListStacks()
if err != nil {
return err
}
stackName := args[0]

if err := stackManager.LoadStack(stackName); err != nil {
return err
if len(args) > 0 {
namedStacks := make([]string, 0, len(args))
for _, stackName := range args {
if contains(allStacks, strings.TrimSpace(stackName)) {
namedStacks = append(namedStacks, stackName)
} else {
fmt.Printf("stack name - %s, is not present on your local machine. Run `ff ls` to see all available stacks.\n", stackName)
}
}

allStacks = namedStacks // replace only the user specified stacks in the slice instead.
}
if err := stackManager.PrintStackInfo(); err != nil {
return err

stackManager := stacks.NewStackManager(ctx)
for _, stackName := range allStacks {
if err := stackManager.LoadStack(stackName); err != nil {
return err
}

if err := stackManager.PrintStacksInfo(); err != nil {
return err
}
}
return nil
},
Expand Down
65 changes: 65 additions & 0 deletions cmd/init_tezos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// 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 (
"context"
"fmt"
"path/filepath"

"github.com/spf13/cobra"

"github.com/hyperledger/firefly-cli/internal/log"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/hyperledger/firefly-cli/pkg/types"
)

var initTezosCmd = &cobra.Command{
Use: "tezos [stack_name] [member_count]",
Short: "Create a new FireFly local dev stack using an Tezos blockchain",
Long: `Create a new FireFly local dev stack using an Tezos blockchain`,
Args: cobra.MaximumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := log.WithVerbosity(context.Background(), verbose)
ctx = log.WithLogger(ctx, logger)
stackManager := stacks.NewStackManager(ctx)
initOptions.BlockchainProvider = types.BlockchainProviderTezos.String()
initOptions.BlockchainConnector = types.BlockchainConnectorTezosconnect.String()
initOptions.BlockchainNodeProvider = types.BlockchainNodeProviderRemoteRPC.String()
// By default we turn off multiparty mode while it's not supported yet
initOptions.MultipartyEnabled = false
initOptions.TokenProviders = []string{}
if err := initCommon(args); err != nil {
return err
}
if err := stackManager.InitStack(&initOptions); err != nil {
stackManager.RemoveStack()
return err
}
fmt.Printf("Stack '%s' created!\nTo start your new stack run:\n\n%s start %s\n", initOptions.StackName, rootCmd.Use, initOptions.StackName)
fmt.Printf("\nYour docker compose file for this stack can be found at: %s\n\n", filepath.Join(stackManager.Stack.StackDir, "docker-compose.yml"))
return nil
},
}

func init() {
initTezosCmd.Flags().IntVar(&initOptions.BlockPeriod, "block-period", -1, "Block period in seconds. Default is variable based on selected blockchain provider.")
initTezosCmd.Flags().StringVar(&initOptions.ContractAddress, "contract-address", "", "Do not automatically deploy a contract, instead use a pre-configured address")
initTezosCmd.Flags().StringVar(&initOptions.RemoteNodeURL, "remote-node-url", "", "For cases where the node is pre-existing and running remotely")

initCmd.AddCommand(initTezosCmd)
}
3 changes: 2 additions & 1 deletion cmd/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var psCmd = &cobra.Command{
Short: "Returns information on running stacks",
Long: `ps returns currently running stacks on your local machine.
It also takes a continuous list of whitespace optional arguement - stack name.`,
It also takes a continuous list of whitespace optional arguement - stack name. If non
is given, it run the "ps" command for all stack on the local machine.`,
Aliases: []string{"process"},
RunE: func(cmd *cobra.Command, args []string) error {

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ module github.com/hyperledger/firefly-cli
go 1.16

require (
blockwatch.cc/tzgo v1.17.1
github.com/briandowns/spinner v1.12.0
github.com/btcsuite/btcd v0.22.1
github.com/google/go-containerregistry v0.8.0
github.com/hyperledger/firefly-common v1.1.2
github.com/hyperledger/firefly-signer v0.9.6
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-isatty v0.0.19
github.com/miracl/conflate v1.2.1
github.com/mitchellh/go-homedir v1.1.0
github.com/otiai10/copy v1.7.0
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.1-0.20220712161005-5247643f0235
github.com/stretchr/testify v1.8.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/crypto v0.10.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)
Loading

0 comments on commit afa66c4

Please sign in to comment.