Skip to content
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

Move command-specific flags into command source file #407

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/provider/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ 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",
Flags: announceHttpFlags,
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 {
Expand Down
10 changes: 10 additions & 0 deletions cmd/provider/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
19 changes: 19 additions & 0 deletions cmd/provider/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
77 changes: 0 additions & 77 deletions cmd/provider/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down Expand Up @@ -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,
}
)
7 changes: 7 additions & 0 deletions cmd/provider/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions cmd/provider/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions cmd/provider/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 6 additions & 0 deletions cmd/provider/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down