Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resloves #271 info command gives more information on stack #272

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 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 @@ -27,10 +28,10 @@ import (
)

var infoCmd = &cobra.Command{
Use: "info <stack_name>",
Use: "info [a 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)
}
75 changes: 75 additions & 0 deletions cmd/ps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright © 2023 Giwa Oluwatobi <[email protected]>
*/
package cmd

import (
"context"
"fmt"
"strings"

"github.com/hyperledger/firefly-cli/internal/log"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
)

// psCmd represents the ps command
var psCmd = &cobra.Command{
Use: "ps [a stack name]...",
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. 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 {

ctx := log.WithVerbosity(context.Background(), verbose)
ctx = log.WithLogger(ctx, logger)

allStacks, err := stacks.ListStacks()
if 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.
}

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

if err := stackManager.IsRunning(); err != nil {
return err
}
}
return nil
},
}

func init() {
rootCmd.AddCommand(psCmd)
}

// contains can be removed if the go mod version is bumped to version Go 1.18
// and replaced with slices.Contains().
func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
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