Skip to content

Commit 14e7721

Browse files
authored
Merge pull request #326 from dwertent/exec-name
chore: Get executable name from the command
2 parents 5771bd4 + cb229e9 commit 14e7721

8 files changed

+21
-15
lines changed

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(), ExecutableName)
5454
}
5555
fmt.Print(account)
5656
fmt.Print("\n")

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{ExecutableName, "create", stackNames})
1515
err := createCmd.Execute()
1616
if err != nil {
1717
t.Fatalf("Failed to create account for testing: %v", err)

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(), ExecutableName)
7676
}
7777
fmt.Print(location)
7878
return nil

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(), ExecutableName)
5555
}
5656
fmt.Print(contractAddress)
5757
return nil

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, ExecutableName)
5454
}
5555
}
5656

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 ExecutableName 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: ExecutableName,
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: ` + ExecutableName + ` init
6669
Optional: Set FIREFLY_HOME env variable for FireFly stack configuration path.
6770
`,
6871
PersistentPreRun: func(cmd *cobra.Command, args []string) {

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 {

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)