generated from kurtosis-tech/package-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: validate command args and set log formatter on fatal error (#122)
* fix: set proper log formatter when fatal error * fix: validate command when invalid args are given
- Loading branch information
1 parent
a1aa8a6
commit 247d5c2
Showing
16 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,13 @@ Copyright © 2023 Hugobyte AI Labs <[email protected]> | |
package bridge | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hugobyte/dive/cli/commands/bridge/relyas" | ||
"github.com/hugobyte/dive/cli/common" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func NewBridgeCmd(diveContext *common.DiveContext) *cobra.Command { | ||
|
@@ -18,7 +22,20 @@ func NewBridgeCmd(diveContext *common.DiveContext) *cobra.Command { | |
This will create an relay to connect two different chains and pass any messages between them.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
cmd.Help() | ||
validArgs := cmd.ValidArgs | ||
for _, c := range cmd.Commands() { | ||
validArgs = append(validArgs, c.Name()) | ||
} | ||
cmd.ValidArgs = validArgs | ||
|
||
if !slices.Contains(cmd.ValidArgs, args[0]) { | ||
|
||
diveContext.Log.SetOutput(os.Stderr) | ||
diveContext.Error(fmt.Sprintf("Invalid Subcommand: %v", args)) | ||
|
||
cmd.Usage() | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ Copyright © 2023 Hugobyte AI Labs<[email protected]> | |
package chain | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"slices" | ||
|
||
"github.com/hugobyte/dive/cli/commands/chain/types" | ||
"github.com/hugobyte/dive/cli/common" | ||
"github.com/spf13/cobra" | ||
|
@@ -21,7 +25,20 @@ By executing this command, the node is launched, enabling network participation, | |
maintenance within the specified blockchain ecosystem.`, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
validArgs := cmd.ValidArgs | ||
for _, c := range cmd.Commands() { | ||
validArgs = append(validArgs, c.Name()) | ||
} | ||
cmd.ValidArgs = validArgs | ||
|
||
if !slices.Contains(cmd.ValidArgs, args[0]) { | ||
|
||
diveContext.Log.SetOutput(os.Stderr) | ||
diveContext.Error(fmt.Sprintf("Invalid Subcommand: %v", args)) | ||
|
||
cmd.Usage() | ||
os.Exit(1) | ||
} | ||
|
||
}, | ||
} | ||
|
@@ -34,3 +51,11 @@ maintenance within the specified blockchain ecosystem.`, | |
return chainCmd | ||
|
||
} | ||
|
||
func addSubcommandsToValidArgs(cmd *cobra.Command) { | ||
validArgs := cmd.ValidArgs | ||
for _, c := range cmd.Commands() { | ||
validArgs = append(validArgs, c.Name()) | ||
} | ||
cmd.ValidArgs = validArgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters