Skip to content

Commit 3d7c6dc

Browse files
committed
Resolves hyperledger#271, info command now output information
about the stack not container. Signed-off-by: tobigiwa <[email protected]>
1 parent e7623ee commit 3d7c6dc

34 files changed

+741
-95
lines changed

cmd/info.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmd
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/hyperledger/firefly-cli/internal/docker"
2425
"github.com/hyperledger/firefly-cli/internal/log"
@@ -27,10 +28,10 @@ import (
2728
)
2829

2930
var infoCmd = &cobra.Command{
30-
Use: "info <stack_name>",
31+
Use: "info [a stack name]...",
3132
Short: "Get info about a stack",
3233
Long: `Get info about a stack such as each container name
33-
and image version.`,
34+
and image version. If non is given, it run the "info" command for all stack on the local machine.`,
3435
RunE: func(cmd *cobra.Command, args []string) error {
3536
ctx := log.WithVerbosity(context.Background(), verbose)
3637
ctx = context.WithValue(ctx, docker.CtxIsLogCmdKey{}, true)
@@ -42,17 +43,33 @@ var infoCmd = &cobra.Command{
4243
}
4344
ctx = context.WithValue(ctx, docker.CtxComposeVersionKey{}, version)
4445

45-
stackManager := stacks.NewStackManager(ctx)
46-
if len(args) == 0 {
47-
return fmt.Errorf("no stack specified")
46+
allStacks, err := stacks.ListStacks()
47+
if err != nil {
48+
return err
4849
}
49-
stackName := args[0]
5050

51-
if err := stackManager.LoadStack(stackName); err != nil {
52-
return err
51+
if len(args) > 0 {
52+
namedStacks := make([]string, 0, len(args))
53+
for _, stackName := range args {
54+
if contains(allStacks, strings.TrimSpace(stackName)) {
55+
namedStacks = append(namedStacks, stackName)
56+
} else {
57+
fmt.Printf("stack name - %s, is not present on your local machine. Run `ff ls` to see all available stacks.\n", stackName)
58+
}
59+
}
60+
61+
allStacks = namedStacks // replace only the user specified stacks in the slice instead.
5362
}
54-
if err := stackManager.PrintStackInfo(); err != nil {
55-
return err
63+
64+
stackManager := stacks.NewStackManager(ctx)
65+
for _, stackName := range allStacks {
66+
if err := stackManager.LoadStack(stackName); err != nil {
67+
return err
68+
}
69+
70+
if err := stackManager.PrintStacksInfo(); err != nil {
71+
return err
72+
}
5673
}
5774
return nil
5875
},

cmd/init_tezos.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright © 2023 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package cmd
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"path/filepath"
23+
24+
"github.com/spf13/cobra"
25+
26+
"github.com/hyperledger/firefly-cli/internal/log"
27+
"github.com/hyperledger/firefly-cli/internal/stacks"
28+
"github.com/hyperledger/firefly-cli/pkg/types"
29+
)
30+
31+
var initTezosCmd = &cobra.Command{
32+
Use: "tezos [stack_name] [member_count]",
33+
Short: "Create a new FireFly local dev stack using an Tezos blockchain",
34+
Long: `Create a new FireFly local dev stack using an Tezos blockchain`,
35+
Args: cobra.MaximumNArgs(2),
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
ctx := log.WithVerbosity(context.Background(), verbose)
38+
ctx = log.WithLogger(ctx, logger)
39+
stackManager := stacks.NewStackManager(ctx)
40+
initOptions.BlockchainProvider = types.BlockchainProviderTezos.String()
41+
initOptions.BlockchainConnector = types.BlockchainConnectorTezosconnect.String()
42+
initOptions.BlockchainNodeProvider = types.BlockchainNodeProviderRemoteRPC.String()
43+
// By default we turn off multiparty mode while it's not supported yet
44+
initOptions.MultipartyEnabled = false
45+
initOptions.TokenProviders = []string{}
46+
if err := initCommon(args); err != nil {
47+
return err
48+
}
49+
if err := stackManager.InitStack(&initOptions); err != nil {
50+
stackManager.RemoveStack()
51+
return err
52+
}
53+
fmt.Printf("Stack '%s' created!\nTo start your new stack run:\n\n%s start %s\n", initOptions.StackName, rootCmd.Use, initOptions.StackName)
54+
fmt.Printf("\nYour docker compose file for this stack can be found at: %s\n\n", filepath.Join(stackManager.Stack.StackDir, "docker-compose.yml"))
55+
return nil
56+
},
57+
}
58+
59+
func init() {
60+
initTezosCmd.Flags().IntVar(&initOptions.BlockPeriod, "block-period", -1, "Block period in seconds. Default is variable based on selected blockchain provider.")
61+
initTezosCmd.Flags().StringVar(&initOptions.ContractAddress, "contract-address", "", "Do not automatically deploy a contract, instead use a pre-configured address")
62+
initTezosCmd.Flags().StringVar(&initOptions.RemoteNodeURL, "remote-node-url", "", "For cases where the node is pre-existing and running remotely")
63+
64+
initCmd.AddCommand(initTezosCmd)
65+
}

cmd/ps.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ var psCmd = &cobra.Command{
1919
Short: "Returns information on running stacks",
2020
Long: `ps returns currently running stacks on your local machine.
2121
22-
It also takes a continuous list of whitespace optional arguement - stack name.`,
22+
It also takes a continuous list of whitespace optional arguement - stack name. If non
23+
is given, it run the "ps" command for all stack on the local machine.`,
2324
Aliases: []string{"process"},
2425
RunE: func(cmd *cobra.Command, args []string) error {
2526

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ module github.com/hyperledger/firefly-cli
1919
go 1.16
2020

2121
require (
22+
blockwatch.cc/tzgo v1.17.1
2223
github.com/briandowns/spinner v1.12.0
2324
github.com/btcsuite/btcd v0.22.1
2425
github.com/google/go-containerregistry v0.8.0
2526
github.com/hyperledger/firefly-common v1.1.2
2627
github.com/hyperledger/firefly-signer v0.9.6
27-
github.com/mattn/go-isatty v0.0.14
28+
github.com/mattn/go-isatty v0.0.19
2829
github.com/miracl/conflate v1.2.1
2930
github.com/mitchellh/go-homedir v1.1.0
3031
github.com/otiai10/copy v1.7.0
3132
github.com/spf13/cobra v1.5.0
3233
github.com/spf13/viper v1.12.1-0.20220712161005-5247643f0235
3334
github.com/stretchr/testify v1.8.0
34-
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
35+
golang.org/x/crypto v0.10.0
3536
gopkg.in/yaml.v2 v2.4.0
3637
gopkg.in/yaml.v3 v3.0.1
3738
)

0 commit comments

Comments
 (0)