From f3d6620eccb0c21225312de59f49ea83a66996c3 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 19 Jan 2022 16:40:20 +0530 Subject: [PATCH] migrate cli to internal package (#301) --- cmd/cli/main.go | 11 +++++++++++ {command => internal/cli}/account.go | 2 +- {command => internal/cli}/account_import.go | 4 ++-- {command => internal/cli}/account_list.go | 4 ++-- {command => internal/cli}/account_new.go | 4 ++-- {command => internal/cli}/chain.go | 2 +- {command => internal/cli}/chain_sethead.go | 6 +++--- command/main.go => internal/cli/command.go | 12 ++++-------- {command => internal/cli}/debug.go | 6 +++--- {command => internal/cli}/flagset/flagset.go | 0 {command => internal/cli}/flagset/flagset_test.go | 0 {command => internal/cli}/peers.go | 2 +- {command => internal/cli}/peers_add.go | 6 +++--- {command => internal/cli}/peers_list.go | 6 +++--- {command => internal/cli}/peers_remove.go | 6 +++--- {command => internal/cli}/peers_status.go | 6 +++--- .../cli}/server/chains/allocs/mainnet.json | 0 .../cli}/server/chains/allocs/mumbai.json | 0 {command => internal/cli}/server/chains/chain.go | 0 {command => internal/cli}/server/chains/mainnet.go | 0 {command => internal/cli}/server/chains/mumbai.go | 0 {command => internal/cli}/server/chains/utils.go | 0 {command => internal/cli}/server/command.go | 0 {command => internal/cli}/server/config.go | 2 +- {command => internal/cli}/server/config_legacy.go | 0 .../cli}/server/config_legacy_test.go | 0 {command => internal/cli}/server/config_test.go | 0 {command => internal/cli}/server/flags.go | 2 +- {command => internal/cli}/server/pprof/pprof.go | 0 {command => internal/cli}/server/proto/server.pb.go | 0 {command => internal/cli}/server/proto/server.proto | 0 .../cli}/server/proto/server_grpc.pb.go | 0 {command => internal/cli}/server/server.go | 2 +- {command => internal/cli}/server/service.go | 4 ++-- {command => internal/cli}/server/service_test.go | 2 +- {command => internal/cli}/server/testdata/simple.hcl | 0 .../cli}/server/testdata/simple.json | 0 {command => internal/cli}/status.go | 4 ++-- {command => internal/cli}/version.go | 2 +- 39 files changed, 51 insertions(+), 44 deletions(-) create mode 100644 cmd/cli/main.go rename {command => internal/cli}/account.go (98%) rename {command => internal/cli}/account_import.go (95%) rename {command => internal/cli}/account_list.go (94%) rename {command => internal/cli}/account_new.go (94%) rename {command => internal/cli}/chain.go (98%) rename {command => internal/cli}/chain_sethead.go (92%) rename command/main.go => internal/cli/command.go (95%) rename {command => internal/cli}/debug.go (97%) rename {command => internal/cli}/flagset/flagset.go (100%) rename {command => internal/cli}/flagset/flagset_test.go (100%) rename {command => internal/cli}/peers.go (98%) rename {command => internal/cli}/peers_add.go (90%) rename {command => internal/cli}/peers_list.go (91%) rename {command => internal/cli}/peers_remove.go (91%) rename {command => internal/cli}/peers_status.go (92%) rename {command => internal/cli}/server/chains/allocs/mainnet.json (100%) rename {command => internal/cli}/server/chains/allocs/mumbai.json (100%) rename {command => internal/cli}/server/chains/chain.go (100%) rename {command => internal/cli}/server/chains/mainnet.go (100%) rename {command => internal/cli}/server/chains/mumbai.go (100%) rename {command => internal/cli}/server/chains/utils.go (100%) rename {command => internal/cli}/server/command.go (100%) rename {command => internal/cli}/server/config.go (99%) rename {command => internal/cli}/server/config_legacy.go (100%) rename {command => internal/cli}/server/config_legacy_test.go (100%) rename {command => internal/cli}/server/config_test.go (100%) rename {command => internal/cli}/server/flags.go (99%) rename {command => internal/cli}/server/pprof/pprof.go (100%) rename {command => internal/cli}/server/proto/server.pb.go (100%) rename {command => internal/cli}/server/proto/server.proto (100%) rename {command => internal/cli}/server/proto/server_grpc.pb.go (100%) rename {command => internal/cli}/server/server.go (99%) rename {command => internal/cli}/server/service.go (97%) rename {command => internal/cli}/server/service_test.go (89%) rename {command => internal/cli}/server/testdata/simple.hcl (100%) rename {command => internal/cli}/server/testdata/simple.json (100%) rename {command => internal/cli}/status.go (96%) rename {command => internal/cli}/version.go (97%) diff --git a/cmd/cli/main.go b/cmd/cli/main.go new file mode 100644 index 0000000000..af4b7d8075 --- /dev/null +++ b/cmd/cli/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "os" + + "github.com/ethereum/go-ethereum/internal/cli" +) + +func main() { + os.Exit(cli.Run(os.Args[1:])) +} diff --git a/command/account.go b/internal/cli/account.go similarity index 98% rename from command/account.go rename to internal/cli/account.go index 747b6b8dba..b8661821d0 100644 --- a/command/account.go +++ b/internal/cli/account.go @@ -1,4 +1,4 @@ -package main +package cli import "github.com/mitchellh/cli" diff --git a/command/account_import.go b/internal/cli/account_import.go similarity index 95% rename from command/account_import.go rename to internal/cli/account_import.go index 331a45aac6..8c9ff40e58 100644 --- a/command/account_import.go +++ b/internal/cli/account_import.go @@ -1,11 +1,11 @@ -package main +package cli import ( "fmt" "github.com/ethereum/go-ethereum/cmd/utils" - "github.com/ethereum/go-ethereum/command/flagset" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" ) type AccountImportCommand struct { diff --git a/command/account_list.go b/internal/cli/account_list.go similarity index 94% rename from command/account_list.go rename to internal/cli/account_list.go index d41e0c0d65..360d41b558 100644 --- a/command/account_list.go +++ b/internal/cli/account_list.go @@ -1,10 +1,10 @@ -package main +package cli import ( "fmt" "github.com/ethereum/go-ethereum/accounts" - "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/internal/cli/flagset" ) type AccountListCommand struct { diff --git a/command/account_new.go b/internal/cli/account_new.go similarity index 94% rename from command/account_new.go rename to internal/cli/account_new.go index 59118a9a37..3334384cb0 100644 --- a/command/account_new.go +++ b/internal/cli/account_new.go @@ -1,9 +1,9 @@ -package main +package cli import ( "fmt" - "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/internal/cli/flagset" ) type AccountNewCommand struct { diff --git a/command/chain.go b/internal/cli/chain.go similarity index 98% rename from command/chain.go rename to internal/cli/chain.go index ed8ca9a5f8..b43f22f999 100644 --- a/command/chain.go +++ b/internal/cli/chain.go @@ -1,4 +1,4 @@ -package main +package cli import ( "github.com/mitchellh/cli" diff --git a/command/chain_sethead.go b/internal/cli/chain_sethead.go similarity index 92% rename from command/chain_sethead.go rename to internal/cli/chain_sethead.go index 0dfed6268b..127ac38f15 100644 --- a/command/chain_sethead.go +++ b/internal/cli/chain_sethead.go @@ -1,12 +1,12 @@ -package main +package cli import ( "context" "fmt" "strconv" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // ChainSetHeadCommand is the command to group the peers commands diff --git a/command/main.go b/internal/cli/command.go similarity index 95% rename from command/main.go rename to internal/cli/command.go index a2e5a629a7..65fe8211dc 100644 --- a/command/main.go +++ b/internal/cli/command.go @@ -1,23 +1,19 @@ -package main +package cli import ( "fmt" "os" "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/ethereum/go-ethereum/node" "github.com/mitchellh/cli" "github.com/ryanuber/columnize" "google.golang.org/grpc" ) -func main() { - os.Exit(Run(os.Args[1:])) -} - func Run(args []string) int { commands := commands() diff --git a/command/debug.go b/internal/cli/debug.go similarity index 97% rename from command/debug.go rename to internal/cli/debug.go index f3f2484b0b..a6b6ff7973 100644 --- a/command/debug.go +++ b/internal/cli/debug.go @@ -1,4 +1,4 @@ -package main +package cli // Based on https://github.com/hashicorp/nomad/blob/main/command/operator_debug.go @@ -16,8 +16,8 @@ import ( "syscall" "time" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/golang/protobuf/jsonpb" gproto "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes/empty" diff --git a/command/flagset/flagset.go b/internal/cli/flagset/flagset.go similarity index 100% rename from command/flagset/flagset.go rename to internal/cli/flagset/flagset.go diff --git a/command/flagset/flagset_test.go b/internal/cli/flagset/flagset_test.go similarity index 100% rename from command/flagset/flagset_test.go rename to internal/cli/flagset/flagset_test.go diff --git a/command/peers.go b/internal/cli/peers.go similarity index 98% rename from command/peers.go rename to internal/cli/peers.go index 4b99288aee..b591366222 100644 --- a/command/peers.go +++ b/internal/cli/peers.go @@ -1,4 +1,4 @@ -package main +package cli import ( "github.com/mitchellh/cli" diff --git a/command/peers_add.go b/internal/cli/peers_add.go similarity index 90% rename from command/peers_add.go rename to internal/cli/peers_add.go index 796b896681..2b2fe127e0 100644 --- a/command/peers_add.go +++ b/internal/cli/peers_add.go @@ -1,10 +1,10 @@ -package main +package cli import ( "context" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // PeersAddCommand is the command to group the peers commands diff --git a/command/peers_list.go b/internal/cli/peers_list.go similarity index 91% rename from command/peers_list.go rename to internal/cli/peers_list.go index af0bc410fa..a42e0011a5 100644 --- a/command/peers_list.go +++ b/internal/cli/peers_list.go @@ -1,12 +1,12 @@ -package main +package cli import ( "context" "fmt" "strings" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // PeersListCommand is the command to group the peers commands diff --git a/command/peers_remove.go b/internal/cli/peers_remove.go similarity index 91% rename from command/peers_remove.go rename to internal/cli/peers_remove.go index 432a35fdcb..979f139251 100644 --- a/command/peers_remove.go +++ b/internal/cli/peers_remove.go @@ -1,10 +1,10 @@ -package main +package cli import ( "context" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // PeersRemoveCommand is the command to group the peers commands diff --git a/command/peers_status.go b/internal/cli/peers_status.go similarity index 92% rename from command/peers_status.go rename to internal/cli/peers_status.go index adb7b2e850..c1da2b2647 100644 --- a/command/peers_status.go +++ b/internal/cli/peers_status.go @@ -1,12 +1,12 @@ -package main +package cli import ( "context" "fmt" "strings" - "github.com/ethereum/go-ethereum/command/flagset" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" ) // PeersStatusCommand is the command to group the peers commands diff --git a/command/server/chains/allocs/mainnet.json b/internal/cli/server/chains/allocs/mainnet.json similarity index 100% rename from command/server/chains/allocs/mainnet.json rename to internal/cli/server/chains/allocs/mainnet.json diff --git a/command/server/chains/allocs/mumbai.json b/internal/cli/server/chains/allocs/mumbai.json similarity index 100% rename from command/server/chains/allocs/mumbai.json rename to internal/cli/server/chains/allocs/mumbai.json diff --git a/command/server/chains/chain.go b/internal/cli/server/chains/chain.go similarity index 100% rename from command/server/chains/chain.go rename to internal/cli/server/chains/chain.go diff --git a/command/server/chains/mainnet.go b/internal/cli/server/chains/mainnet.go similarity index 100% rename from command/server/chains/mainnet.go rename to internal/cli/server/chains/mainnet.go diff --git a/command/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go similarity index 100% rename from command/server/chains/mumbai.go rename to internal/cli/server/chains/mumbai.go diff --git a/command/server/chains/utils.go b/internal/cli/server/chains/utils.go similarity index 100% rename from command/server/chains/utils.go rename to internal/cli/server/chains/utils.go diff --git a/command/server/command.go b/internal/cli/server/command.go similarity index 100% rename from command/server/command.go rename to internal/cli/server/command.go diff --git a/command/server/config.go b/internal/cli/server/config.go similarity index 99% rename from command/server/config.go rename to internal/cli/server/config.go index c9ffff481d..457ee53aa9 100644 --- a/command/server/config.go +++ b/internal/cli/server/config.go @@ -14,12 +14,12 @@ import ( godebug "runtime/debug" - "github.com/ethereum/go-ethereum/command/server/chains" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/fdlimit" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/eth/gasprice" + "github.com/ethereum/go-ethereum/internal/cli/server/chains" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" diff --git a/command/server/config_legacy.go b/internal/cli/server/config_legacy.go similarity index 100% rename from command/server/config_legacy.go rename to internal/cli/server/config_legacy.go diff --git a/command/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go similarity index 100% rename from command/server/config_legacy_test.go rename to internal/cli/server/config_legacy_test.go diff --git a/command/server/config_test.go b/internal/cli/server/config_test.go similarity index 100% rename from command/server/config_test.go rename to internal/cli/server/config_test.go diff --git a/command/server/flags.go b/internal/cli/server/flags.go similarity index 99% rename from command/server/flags.go rename to internal/cli/server/flags.go index 76828ef6fc..09e5a7bf78 100644 --- a/command/server/flags.go +++ b/internal/cli/server/flags.go @@ -1,7 +1,7 @@ package server import ( - "github.com/ethereum/go-ethereum/command/flagset" + "github.com/ethereum/go-ethereum/internal/cli/flagset" ) func (c *Command) Flags() *flagset.Flagset { diff --git a/command/server/pprof/pprof.go b/internal/cli/server/pprof/pprof.go similarity index 100% rename from command/server/pprof/pprof.go rename to internal/cli/server/pprof/pprof.go diff --git a/command/server/proto/server.pb.go b/internal/cli/server/proto/server.pb.go similarity index 100% rename from command/server/proto/server.pb.go rename to internal/cli/server/proto/server.pb.go diff --git a/command/server/proto/server.proto b/internal/cli/server/proto/server.proto similarity index 100% rename from command/server/proto/server.proto rename to internal/cli/server/proto/server.proto diff --git a/command/server/proto/server_grpc.pb.go b/internal/cli/server/proto/server_grpc.pb.go similarity index 100% rename from command/server/proto/server_grpc.pb.go rename to internal/cli/server/proto/server_grpc.pb.go diff --git a/command/server/server.go b/internal/cli/server/server.go similarity index 99% rename from command/server/server.go rename to internal/cli/server/server.go index afc0550b2a..67c335dff4 100644 --- a/command/server/server.go +++ b/internal/cli/server/server.go @@ -11,11 +11,11 @@ import ( "time" "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethstats" "github.com/ethereum/go-ethereum/graphql" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics/influxdb" diff --git a/command/server/service.go b/internal/cli/server/service.go similarity index 97% rename from command/server/service.go rename to internal/cli/server/service.go index fe70029aa9..6973705ebe 100644 --- a/command/server/service.go +++ b/internal/cli/server/service.go @@ -7,9 +7,9 @@ import ( "reflect" "strings" - "github.com/ethereum/go-ethereum/command/server/pprof" - "github.com/ethereum/go-ethereum/command/server/proto" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/internal/cli/server/pprof" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" gproto "github.com/golang/protobuf/proto" diff --git a/command/server/service_test.go b/internal/cli/server/service_test.go similarity index 89% rename from command/server/service_test.go rename to internal/cli/server/service_test.go index 715401b12b..7850525686 100644 --- a/command/server/service_test.go +++ b/internal/cli/server/service_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/stretchr/testify/assert" ) diff --git a/command/server/testdata/simple.hcl b/internal/cli/server/testdata/simple.hcl similarity index 100% rename from command/server/testdata/simple.hcl rename to internal/cli/server/testdata/simple.hcl diff --git a/command/server/testdata/simple.json b/internal/cli/server/testdata/simple.json similarity index 100% rename from command/server/testdata/simple.json rename to internal/cli/server/testdata/simple.json diff --git a/command/status.go b/internal/cli/status.go similarity index 96% rename from command/status.go rename to internal/cli/status.go index ddfdb50daa..ef0a42172b 100644 --- a/command/status.go +++ b/internal/cli/status.go @@ -1,11 +1,11 @@ -package main +package cli import ( "context" "fmt" "strings" - "github.com/ethereum/go-ethereum/command/server/proto" + "github.com/ethereum/go-ethereum/internal/cli/server/proto" "github.com/golang/protobuf/ptypes/empty" ) diff --git a/command/version.go b/internal/cli/version.go similarity index 97% rename from command/version.go rename to internal/cli/version.go index 5483ea5402..7433f208b2 100644 --- a/command/version.go +++ b/internal/cli/version.go @@ -1,4 +1,4 @@ -package main +package cli import ( "github.com/ethereum/go-ethereum/params"