-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add CLI commands on binary #616
Changes from all commits
68294f0
9161cda
372d44e
0fc53ba
5c71c61
5dd069a
d088bb2
af191ee
7fcf3cb
10a0feb
d145aff
60f024d
f25329a
218d8b9
de89bb1
f2c6fcc
122367b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ check-tidy: | |
go mod tidy | ||
git diff --exit-code | ||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=1 go build -o flow-evm-gateway -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$(shell git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" cmd/main.go | ||
chmod a+x flow-evm-gateway | ||
|
||
.PHONY: fix-lint | ||
fix-lint: | ||
golangci-lint run -v --fix ./... | ||
|
@@ -45,7 +50,24 @@ start: | |
start-local: | ||
rm -rf db/ | ||
rm -rf metrics/data/ | ||
go run cmd/main/main.go \ | ||
go run cmd/main.go run \ | ||
--flow-network-id=flow-emulator \ | ||
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \ | ||
--coa-address=f8d6e0586b0a20c7 \ | ||
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \ | ||
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \ | ||
--coa-resource-create=true \ | ||
--gas-price=0 \ | ||
--log-writer=console \ | ||
--profiler-enabled=true \ | ||
--profiler-port=6060 | ||
m-Peter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Use this after running `make build`, to test out the binary | ||
.PHONY: start-local-bin | ||
start-local-bin: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a comment for when you would use what would be nice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point 👍 |
||
rm -rf db/ | ||
rm -rf metrics/data/ | ||
./flow-evm-gateway run \ | ||
--flow-network-id=flow-emulator \ | ||
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \ | ||
--coa-address=f8d6e0586b0a20c7 \ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||
package main | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
"github.com/onflow/flow-evm-gateway/cmd/run" | ||||||||||||||||||||||||||||||
"github.com/onflow/flow-evm-gateway/cmd/version" | ||||||||||||||||||||||||||||||
"github.com/rs/zerolog/log" | ||||||||||||||||||||||||||||||
"github.com/spf13/cobra" | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
var rootCmd = &cobra.Command{ | ||||||||||||||||||||||||||||||
Use: "", | ||||||||||||||||||||||||||||||
Short: "Utility commands for the EVM Gateway Node", | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
m-Peter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func Execute() { | ||||||||||||||||||||||||||||||
if err := rootCmd.Execute(); err != nil { | ||||||||||||||||||||||||||||||
log.Err(err).Msg("failed to run command") | ||||||||||||||||||||||||||||||
os.Exit(1) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider enhancing error handling in the Execute function. While the current implementation is functional, consider the following improvements:
- log.Err(err).Msg("failed to run command")
+ log.Err(err).Str("command", os.Args[0]).Msg("failed to execute command")
-func Execute() {
+func Execute() error {
if err := rootCmd.Execute(); err != nil {
log.Err(err).Str("command", os.Args[0]).Msg("failed to execute command")
- os.Exit(1)
+ return err
}
+ return nil
} These changes will provide more informative logs and improve the function's flexibility and testability. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func main() { | ||||||||||||||||||||||||||||||
rootCmd.AddCommand(version.Cmd) | ||||||||||||||||||||||||||||||
rootCmd.AddCommand(run.Cmd) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Execute() | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+24
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling in the main function. The main function currently doesn't handle potential errors from the Execute function. Consider the following improvement: func main() {
rootCmd.AddCommand(version.Cmd)
rootCmd.AddCommand(run.Cmd)
- Execute()
+ if err := Execute(); err != nil {
+ os.Exit(1)
+ }
} This change ensures that if Execute returns an error, the program will exit with a non-zero status code, which is a common practice for indicating failure in CLI applications. 📝 Committable suggestion
Suggested change
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Missing 'run' and 'version' command implementations
The build command includes
version
andrun
commands, but their implementations are not found incmd/main.go
. Please ensure these commands are properly implemented to align with the PR objectives.🔗 Analysis chain
Build command updated to support versioning and CGO
The build command has been modified to include version information and enable CGO. This change aligns with the PR objective of adding a version command to the binary.
A few points to note:
version
command../cmd/main/main.go
tocmd/main.go
, suggesting a restructure of the project layout.Let's verify if the new project structure is consistent:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 468