Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9e3f0ee

Browse files
committedSep 11, 2024
chore: Get executable name from the command
Signed-off-by: dwertent <david.wertenteil@kaleido.io>
1 parent a459b82 commit 9e3f0ee

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed
 

Diff for: ‎Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ GOBIN := $(shell $(VGO) env GOPATH)/bin
1919
GITREF := $(shell git rev-parse --short HEAD)
2020
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
2121
LINT := $(GOBIN)/golangci-lint
22+
EXEC := ff # consider cahaning the default name of the executable to 'firefly'
2223

2324
all: format build lint test tidy
2425
format: ## Formats all go code
2526
gofmt -s -w .
2627
test: deps
2728
$(VGO) test ./internal/... ./pkg/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s ${TEST_ARGS}
2829
build: ## Builds all go code
29-
cd ff && go build -ldflags="-X 'github.com/hyperledger/firefly-cli/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly-cli/cmd.BuildCommit=$(GITREF)'"
30+
cd ff && go build -ldflags="-X 'github.com/hyperledger/firefly-cli/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly-cli/cmd.BuildCommit=$(GITREF)'" -o ../$(EXEC)
3031
install: ## Installs the package
31-
cd ff && go install -ldflags="-X 'github.com/hyperledger/firefly-cli/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly-cli/cmd.BuildCommit=$(GITREF)'"
32+
cd ff && go install -ldflags="-X 'github.com/hyperledger/firefly-cli/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly-cli/cmd.BuildCommit=$(GITREF)'" -o ../$(EXEC)
3233

3334
lint: ${LINT} ## Checks and reports lint errors
3435
GOGC=20 $(LINT) run -v --timeout 5m

Diff for: ‎cmd/accounts_create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var accountsCreateCmd = &cobra.Command{
5050
}
5151
account, err := stackManager.CreateAccount(args[1:])
5252
if err != nil {
53-
return err
53+
return fmt.Errorf("%s. usage: %s accounts create <stack_name> <org_name> <account_name>", err.Error(), ExecFileName)
5454
}
5555
fmt.Print(account)
5656
fmt.Print("\n")

Diff for: ‎cmd/accounts_list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestAccountListCmd(t *testing.T) {
1111
testNames := []string{"stack-1", "stack-2", "stack-3", "stack-4", "stack-5"}
1212
for _, stackNames := range testNames {
1313
createCmd := accountsCreateCmd
14-
createCmd.SetArgs([]string{"ff", "create", stackNames})
14+
createCmd.SetArgs([]string{ExecFileName, "create", stackNames})
1515
err := createCmd.Execute()
1616
if err != nil {
1717
t.Fatalf("Failed to create account for testing: %v", err)

Diff for: ‎cmd/deploy_ethereum.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ solc --combined-json abi,bin contract.sol > contract.json
7272
}
7373
location, err := stackManager.DeployContract(filename, selectedContractName, 0, args[2:])
7474
if err != nil {
75-
return err
75+
return fmt.Errorf("%s. usage: %s deploy <stack_name> <filename> <channel> <chaincode> <version>", err.Error(), ExecFileName)
7676
}
7777
fmt.Print(location)
7878
return nil

Diff for: ‎cmd/deploy_fabric.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var deployFabricCmd = &cobra.Command{
5151
}
5252
contractAddress, err := stackManager.DeployContract(filename, filename, 0, args[2:])
5353
if err != nil {
54-
return err
54+
return fmt.Errorf("%s. usage: %s deploy <stack_name> <filename> <channel> <chaincode> <version>", err.Error(), ExecFileName)
5555
}
5656
fmt.Print(contractAddress)
5757
return nil

Diff for: ‎cmd/ps.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var psCmd = &cobra.Command{
5050
if contains(allStacks, strings.TrimSpace(stackName)) {
5151
namedStacks = append(namedStacks, stackName)
5252
} else {
53-
fmt.Printf("stack name - %s, is not present on your local machine. Run `ff ls` to see all available stacks.\n", stackName)
53+
fmt.Printf("stack name - %s, is not present on your local machine. Run `%s ls` to see all available stacks.\n", stackName, ExecFileName)
5454
}
5555
}
5656

Diff for: ‎cmd/root.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ var logger log.Logger = &log.StdoutLogger{
3939
LogLevel: log.Debug,
4040
}
4141

42+
// name of the executable, this is for the help messages
43+
var ExecFileName string = os.Args[0]
44+
4245
func GetFireflyASCIIArt() string {
4346
s := ""
4447
s += "\u001b[33m _______ ________ \u001b[0m\n" // yellow
@@ -53,7 +56,7 @@ func GetFireflyASCIIArt() string {
5356

5457
// rootCmd represents the base command when called without any subcommands
5558
var rootCmd = &cobra.Command{
56-
Use: "ff",
59+
Use: ExecFileName,
5760
Short: "FireFly CLI is a developer tool used to manage local development stacks",
5861
Long: GetFireflyASCIIArt() + `
5962
FireFly CLI is a developer tool used to manage local development stacks
@@ -62,7 +65,7 @@ This tool automates creation of stacks with many infrastructure components which
6265
would otherwise be a time consuming manual task. It also wraps docker compose
6366
commands to manage the lifecycle of stacks.
6467
65-
To get started run: ff init
68+
To get started run: ` + ExecFileName + ` init
6669
Optional: Set FIREFLY_HOME env variable for FireFly stack configuration path.
6770
`,
6871
PersistentPreRun: func(cmd *cobra.Command, args []string) {

Diff for: ‎cmd/version.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ import (
2828
var shortened = false
2929
var output = "json"
3030

31-
var BuildDate string // set by go-releaser
32-
var BuildCommit string // set by go-releaser
33-
var BuildVersionOverride string // set by go-releaser
31+
// set by go-releaser
32+
var (
33+
BuildDate string
34+
BuildCommit string
35+
BuildVersionOverride string
36+
)
3437

3538
// Info creates a formattable struct for version output
3639
type Info struct {

Diff for: ‎internal/blockchain/fabric/fabric_provider.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,11 @@ func (p *FabricProvider) DeployContract(filename, contractName, instanceName str
522522
}
523523
switch {
524524
case len(extraArgs) < 1:
525-
return nil, fmt.Errorf("channel not set. usage: ff deploy <stack_name> <filename> <channel> <chaincode> <version>")
525+
return nil, fmt.Errorf("channel not set")
526526
case len(extraArgs) < 2:
527-
return nil, fmt.Errorf("chaincode not set. usage: ff deploy <stack_name> <filename> <channel> <chaincode> <version>")
527+
return nil, fmt.Errorf("chaincode not set")
528528
case len(extraArgs) < 3:
529-
return nil, fmt.Errorf("version not set. usage: ff deploy <stack_name> <filename> <channel> <chaincode> <version>")
529+
return nil, fmt.Errorf("version not set")
530530
}
531531
channel := extraArgs[0]
532532
chaincode := extraArgs[1]
@@ -587,9 +587,9 @@ func (p *FabricProvider) CreateAccount(args []string) (interface{}, error) {
587587
}
588588
switch {
589589
case len(args) < 1:
590-
return "", fmt.Errorf("org name not set. usage: ff accounts create <stack_name> <org_name> <account_name>")
590+
return "", fmt.Errorf("org name not set")
591591
case len(args) < 2:
592-
return "", fmt.Errorf("account name not set. usage: ff accounts create <stack_name> <org_name> <account_name>")
592+
return "", fmt.Errorf("account name not set")
593593
}
594594
orgName := args[0]
595595
accountName := args[1]

0 commit comments

Comments
 (0)