From d1a5755e604ca42fafcd56850116a2302b01bebe Mon Sep 17 00:00:00 2001 From: gammazero Date: Thu, 31 Aug 2023 23:08:48 -0700 Subject: [PATCH] Move command-specific flags into command source file --- cmd/provider/announce.go | 9 +++++ cmd/provider/connect.go | 10 ++++++ cmd/provider/daemon.go | 19 ++++++++++ cmd/provider/flags.go | 77 ---------------------------------------- cmd/provider/import.go | 7 ++++ cmd/provider/index.go | 21 +++++++++++ cmd/provider/init.go | 2 ++ cmd/provider/remove.go | 6 ++++ 8 files changed, 74 insertions(+), 77 deletions(-) diff --git a/cmd/provider/announce.go b/cmd/provider/announce.go index 71c15dc6..1d34587e 100644 --- a/cmd/provider/announce.go +++ b/cmd/provider/announce.go @@ -17,6 +17,10 @@ var AnnounceCmd = &cli.Command{ Action: announceCommand, } +var announceFlags = []cli.Flag{ + adminAPIFlag, +} + var AnnounceHttpCmd = &cli.Command{ Name: "announce-http", Usage: "Publish an announcement message for the latest advertisement to a specific indexer via http", @@ -24,6 +28,11 @@ var AnnounceHttpCmd = &cli.Command{ Action: announceHttpCommand, } +var announceHttpFlags = []cli.Flag{ + adminAPIFlag, + indexerFlag, +} + func announceCommand(cctx *cli.Context) error { req, err := http.NewRequestWithContext(cctx.Context, http.MethodPost, adminAPIFlagValue+"/admin/announce", nil) if err != nil { diff --git a/cmd/provider/connect.go b/cmd/provider/connect.go index 81daa4fc..d8f27839 100644 --- a/cmd/provider/connect.go +++ b/cmd/provider/connect.go @@ -15,6 +15,16 @@ var ConnectCmd = &cli.Command{ Action: connectCommand, } +var connectFlags = []cli.Flag{ + &cli.StringFlag{ + Name: "indexermaddr", + Usage: "Indexer multiaddr to connect", + Aliases: []string{"imaddr"}, + Required: true, + }, + adminAPIFlag, +} + func connectCommand(cctx *cli.Context) error { iaddr := cctx.String("indexermaddr") req := &adminserver.ConnectReq{Maddr: iaddr} diff --git a/cmd/provider/daemon.go b/cmd/provider/daemon.go index 683195f2..a6454f93 100644 --- a/cmd/provider/daemon.go +++ b/cmd/provider/daemon.go @@ -54,6 +54,25 @@ var DaemonCmd = &cli.Command{ Action: daemonCommand, } +var carZeroLengthAsEOFFlagValue bool + +var daemonFlags = []cli.Flag{ + &cli.BoolFlag{ + Name: "carZeroLengthAsEOF", + Aliases: []string{"cz"}, + Usage: "Specifies whether zero-length blocks in CAR should be consideted as EOF.", + Value: false, // Default to disabled, consistent with go-car/v2 defaults. + Destination: &carZeroLengthAsEOFFlagValue, + }, + &cli.StringFlag{ + Name: "log-level", + Usage: "Set the log level", + EnvVars: []string{"GOLOG_LOG_LEVEL"}, + Value: "info", + Required: false, + }, +} + var tempBootstrapPeersKey = datastore.NewKey("/local/temp_bootstrap_peers") func daemonCommand(cctx *cli.Context) error { diff --git a/cmd/provider/flags.go b/cmd/provider/flags.go index 218c461a..b8db2ae1 100644 --- a/cmd/provider/flags.go +++ b/cmd/provider/flags.go @@ -4,38 +4,6 @@ import ( "github.com/urfave/cli/v2" ) -var announceFlags = []cli.Flag{ - adminAPIFlag, -} - -var announceHttpFlags = []cli.Flag{ - adminAPIFlag, - indexerFlag, -} - -var daemonFlags = []cli.Flag{ - carZeroLengthAsEOFFlag, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set the log level", - EnvVars: []string{"GOLOG_LOG_LEVEL"}, - Value: "info", - Required: false, - }, -} - -var initFlags = []cli.Flag{} - -var connectFlags = []cli.Flag{ - &cli.StringFlag{ - Name: "indexermaddr", - Usage: "Indexer multiaddr to connect", - Aliases: []string{"imaddr"}, - Required: true, - }, - adminAPIFlag, -} - var indexerFlag = &cli.StringFlag{ Name: "indexer", Usage: "Host or host:port of indexer to use", @@ -50,40 +18,6 @@ var addrFlag = &cli.StringSliceFlag{ Required: true, } -var indexFlags = []cli.Flag{ - indexerFlag, - addrFlag, - &cli.StringFlag{ - Name: "mh", - Usage: "Specify multihash to use as indexer key", - Required: false, - }, - &cli.StringFlag{ - Name: "cid", - Usage: "Specify CID to use as indexer key", - Required: false, - }, - &cli.StringFlag{ - Name: "ctxid", - Usage: "Context ID", - Required: true, - }, - metadataFlag, -} - -var importCarFlags = []cli.Flag{ - adminAPIFlag, - carPathFlag, - metadataFlag, - keyFlag, -} - -var removeCarFlags = []cli.Flag{ - adminAPIFlag, - optionalCarPathFlag, - keyFlag, -} - var ( metadataFlagValue string metadataFlag = &cli.StringFlag{ @@ -138,14 +72,3 @@ var ( Destination: &adminAPIFlagValue, } ) - -var ( - carZeroLengthAsEOFFlagValue bool - carZeroLengthAsEOFFlag = &cli.BoolFlag{ - Name: "carZeroLengthAsEOF", - Aliases: []string{"cz"}, - Usage: "Specifies whether zero-length blocks in CAR should be consideted as EOF.", - Value: false, // Default to disabled, consistent with go-car/v2 defaults. - Destination: &carZeroLengthAsEOFFlagValue, - } -) diff --git a/cmd/provider/import.go b/cmd/provider/import.go index 5cd3a229..d1c78283 100644 --- a/cmd/provider/import.go +++ b/cmd/provider/import.go @@ -35,6 +35,13 @@ var ( md = metadata.Default.New() ) +var importCarFlags = []cli.Flag{ + adminAPIFlag, + carPathFlag, + metadataFlag, + keyFlag, +} + func beforeImportCar(cctx *cli.Context) error { if cctx.IsSet(keyFlag.Name) { decoded, err := base64.StdEncoding.DecodeString(keyFlagValue) diff --git a/cmd/provider/index.go b/cmd/provider/index.go index 22b568d8..90d979ba 100644 --- a/cmd/provider/index.go +++ b/cmd/provider/index.go @@ -21,6 +21,27 @@ var IndexCmd = &cli.Command{ Action: indexCommand, } +var indexFlags = []cli.Flag{ + addrFlag, + indexerFlag, + &cli.StringFlag{ + Name: "mh", + Usage: "Specify multihash to use as indexer key", + Required: false, + }, + &cli.StringFlag{ + Name: "cid", + Usage: "Specify CID to use as indexer key", + Required: false, + }, + &cli.StringFlag{ + Name: "ctxid", + Usage: "Context ID", + Required: true, + }, + metadataFlag, +} + func indexCommand(cctx *cli.Context) error { mhArg := cctx.String("mh") cidArg := cctx.String("cid") diff --git a/cmd/provider/init.go b/cmd/provider/init.go index 59752dad..9aad9976 100644 --- a/cmd/provider/init.go +++ b/cmd/provider/init.go @@ -16,6 +16,8 @@ var InitCmd = &cli.Command{ Action: initCommand, } +var initFlags = []cli.Flag{} + func initCommand(cctx *cli.Context) error { log.Info("Initializing provider config file") diff --git a/cmd/provider/remove.go b/cmd/provider/remove.go index d3dfc094..3191eda3 100644 --- a/cmd/provider/remove.go +++ b/cmd/provider/remove.go @@ -41,6 +41,12 @@ specified, they key is simply calculated as the SHA_256 hash of the given path.` Before: beforeRemoveCar, Action: doRemoveCar, } + + removeCarFlags = []cli.Flag{ + adminAPIFlag, + optionalCarPathFlag, + keyFlag, + } ) func beforeRemoveCar(cctx *cli.Context) error {