2022-05-18 09:22:02 +00:00
|
|
|
package commonflags
|
|
|
|
|
|
|
|
import (
|
2022-10-05 07:39:47 +00:00
|
|
|
"time"
|
|
|
|
|
2022-05-18 09:22:02 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Common CLI flag keys, shorthands, default
|
|
|
|
// values and their usage descriptions.
|
|
|
|
const (
|
|
|
|
GenerateKey = "generate-key"
|
2024-05-28 12:08:28 +00:00
|
|
|
GenerateKeyShorthand = "g"
|
|
|
|
GenerateKeyDefault = false
|
|
|
|
GenerateKeyUsage = "Generate new private key"
|
2022-05-18 09:22:02 +00:00
|
|
|
|
|
|
|
WalletPath = "wallet"
|
|
|
|
WalletPathShorthand = "w"
|
|
|
|
WalletPathDefault = ""
|
2022-10-11 14:02:03 +00:00
|
|
|
WalletPathUsage = "Path to the wallet or binary key"
|
2022-05-18 09:22:02 +00:00
|
|
|
|
|
|
|
Account = "address"
|
|
|
|
AccountShorthand = ""
|
|
|
|
AccountDefault = ""
|
2022-10-11 14:02:03 +00:00
|
|
|
AccountUsage = "Address of wallet account"
|
2022-05-18 09:22:02 +00:00
|
|
|
|
|
|
|
RPC = "rpc-endpoint"
|
|
|
|
RPCShorthand = "r"
|
|
|
|
RPCDefault = ""
|
2022-10-11 14:02:03 +00:00
|
|
|
RPCUsage = "Remote node address (as 'multiaddr' or '<host>:<port>')"
|
2022-05-18 09:22:02 +00:00
|
|
|
|
2022-10-05 07:39:47 +00:00
|
|
|
Timeout = "timeout"
|
|
|
|
TimeoutShorthand = "t"
|
|
|
|
TimeoutDefault = 15 * time.Second
|
2022-10-11 14:02:03 +00:00
|
|
|
TimeoutUsage = "Timeout for an operation"
|
2022-10-05 07:39:47 +00:00
|
|
|
|
2022-05-18 09:22:02 +00:00
|
|
|
Verbose = "verbose"
|
|
|
|
VerboseShorthand = "v"
|
2022-10-11 14:02:03 +00:00
|
|
|
VerboseUsage = "Verbose output"
|
2022-09-27 06:49:45 +00:00
|
|
|
|
|
|
|
ForceFlag = "force"
|
|
|
|
ForceFlagShorthand = "f"
|
2022-10-18 11:43:04 +00:00
|
|
|
|
|
|
|
CIDFlag = "cid"
|
|
|
|
CIDFlagUsage = "Container ID."
|
|
|
|
|
|
|
|
OIDFlag = "oid"
|
|
|
|
OIDFlagUsage = "Object ID."
|
2023-05-24 11:50:19 +00:00
|
|
|
|
|
|
|
TracingFlag = "trace"
|
|
|
|
TracingFlagUsage = "Generate trace ID and print it."
|
2024-06-20 13:04:55 +00:00
|
|
|
|
|
|
|
AwaitFlag = "await"
|
|
|
|
AwaitFlagUsage = "Wait for the operation to complete"
|
2024-07-08 15:04:30 +00:00
|
|
|
|
|
|
|
QuietFlag = "quiet"
|
|
|
|
QuietFlagShorthand = "q"
|
|
|
|
QuietFlagUsage = "Print nothing and exit with non-zero code on failure"
|
2022-05-18 09:22:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Init adds common flags to the command:
|
2022-10-17 12:03:55 +00:00
|
|
|
// - GenerateKey,
|
|
|
|
// - WalletPath,
|
|
|
|
// - Account,
|
|
|
|
// - RPC,
|
2023-05-24 11:50:19 +00:00
|
|
|
// - Tracing,
|
2022-10-17 12:03:55 +00:00
|
|
|
// - Timeout.
|
2022-05-18 09:22:02 +00:00
|
|
|
func Init(cmd *cobra.Command) {
|
|
|
|
InitWithoutRPC(cmd)
|
|
|
|
|
|
|
|
ff := cmd.Flags()
|
|
|
|
ff.StringP(RPC, RPCShorthand, RPCDefault, RPCUsage)
|
2023-05-24 11:50:19 +00:00
|
|
|
ff.Bool(TracingFlag, false, TracingFlagUsage)
|
2022-10-05 07:39:47 +00:00
|
|
|
ff.DurationP(Timeout, TimeoutShorthand, TimeoutDefault, TimeoutUsage)
|
2022-05-18 09:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InitWithoutRPC is similar to Init but doesn't create the RPC flag.
|
|
|
|
func InitWithoutRPC(cmd *cobra.Command) {
|
|
|
|
ff := cmd.Flags()
|
|
|
|
|
2024-05-28 12:08:28 +00:00
|
|
|
ff.BoolP(GenerateKey, GenerateKeyShorthand, GenerateKeyDefault, GenerateKeyUsage)
|
2022-05-18 09:22:02 +00:00
|
|
|
ff.StringP(WalletPath, WalletPathShorthand, WalletPathDefault, WalletPathUsage)
|
|
|
|
ff.StringP(Account, AccountShorthand, AccountDefault, AccountUsage)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind binds common command flags to the viper.
|
|
|
|
func Bind(cmd *cobra.Command) {
|
|
|
|
ff := cmd.Flags()
|
|
|
|
|
|
|
|
_ = viper.BindPFlag(GenerateKey, ff.Lookup(GenerateKey))
|
|
|
|
_ = viper.BindPFlag(WalletPath, ff.Lookup(WalletPath))
|
|
|
|
_ = viper.BindPFlag(Account, ff.Lookup(Account))
|
|
|
|
_ = viper.BindPFlag(RPC, ff.Lookup(RPC))
|
2022-10-05 07:39:47 +00:00
|
|
|
_ = viper.BindPFlag(Timeout, ff.Lookup(Timeout))
|
2022-05-18 09:22:02 +00:00
|
|
|
}
|