[#12] cli: clarify -g usage in container list

Add usage replacement for `container list -g` and verbose
warning when using `-g` without `--owner`.

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2024-05-28 15:08:28 +03:00
parent 3627b44e92
commit cc3f762cf2
2 changed files with 12 additions and 4 deletions

View file

@ -11,9 +11,9 @@ import (
// values and their usage descriptions.
const (
GenerateKey = "generate-key"
generateKeyShorthand = "g"
generateKeyDefault = false
generateKeyUsage = "Generate new private key"
GenerateKeyShorthand = "g"
GenerateKeyDefault = false
GenerateKeyUsage = "Generate new private key"
WalletPath = "wallet"
WalletPathShorthand = "w"
@ -72,7 +72,7 @@ func Init(cmd *cobra.Command) {
func InitWithoutRPC(cmd *cobra.Command) {
ff := cmd.Flags()
ff.BoolP(GenerateKey, generateKeyShorthand, generateKeyDefault, generateKeyUsage)
ff.BoolP(GenerateKey, GenerateKeyShorthand, GenerateKeyDefault, GenerateKeyUsage)
ff.StringP(WalletPath, WalletPathShorthand, WalletPathDefault, WalletPathUsage)
ff.StringP(Account, AccountShorthand, AccountDefault, AccountUsage)
}

View file

@ -18,6 +18,8 @@ const (
flagListPrintAttr = "with-attr"
flagListContainerOwner = "owner"
flagListName = "name"
generateKeyContainerUsage = commonflags.GenerateKeyUsage + ", should be used with --owner flag"
)
// flag vars of list command.
@ -34,6 +36,11 @@ var listContainersCmd = &cobra.Command{
Run: func(cmd *cobra.Command, _ []string) {
var idUser user.ID
generateKey, _ := cmd.Flags().GetBool(commonflags.GenerateKey)
if flagVarListContainerOwner == "" && generateKey {
cmd.PrintErrln("WARN: using -g without --owner - output will be empty")
}
key := key.GetOrGenerate(cmd)
if flagVarListContainerOwner == "" {
@ -104,4 +111,5 @@ func initContainerListContainersCmd() {
flags.BoolVar(&flagVarListPrintAttr, flagListPrintAttr, false,
"Request and print attributes of each container",
)
flags.Lookup(commonflags.GenerateKey).Usage = generateKeyContainerUsage
}