(cmd *cobra.Command)
| 39 | } |
| 40 | |
| 41 | func sharedLinkPasswordFromFlags(cmd *cobra.Command) (sharedLinkPasswordOptions, error) { |
| 42 | var sourceCount int |
| 43 | passwordChanged := localFlagChanged(cmd, "password") |
| 44 | if passwordChanged { |
| 45 | sourceCount++ |
| 46 | } |
| 47 | |
| 48 | passwordPrompt, err := localBoolFlag(cmd, "password-prompt") |
| 49 | if err != nil { |
| 50 | return sharedLinkPasswordOptions{}, err |
| 51 | } |
| 52 | if passwordPrompt { |
| 53 | sourceCount++ |
| 54 | } |
| 55 | |
| 56 | passwordFile, err := localStringFlag(cmd, "password-file") |
| 57 | if err != nil { |
| 58 | return sharedLinkPasswordOptions{}, err |
| 59 | } |
| 60 | if passwordFile != "" { |
| 61 | sourceCount++ |
| 62 | } |
| 63 | |
| 64 | if sourceCount == 0 { |
| 65 | return sharedLinkPasswordOptions{}, nil |
| 66 | } |
| 67 | if sourceCount > 1 { |
| 68 | return sharedLinkPasswordOptions{}, invalidArgumentsErrorWithDetails("use only one of `--password`, `--password-prompt`, or `--password-file`", flagsErrorDetails("password", "password-prompt", "password-file")) |
| 69 | } |
| 70 | |
| 71 | var password string |
| 72 | switch { |
| 73 | case passwordChanged: |
| 74 | password, err = cmd.Flags().GetString("password") |
| 75 | case passwordPrompt: |
| 76 | password, err = readSharedLinkPassword("Shared link password: ", cmd.InOrStdin(), cmd.ErrOrStderr()) |
| 77 | default: |
| 78 | password, err = sharedLinkPasswordFromFile(passwordFile) |
| 79 | } |
| 80 | if err != nil { |
| 81 | return sharedLinkPasswordOptions{}, err |
| 82 | } |
| 83 | if password == "" { |
| 84 | return sharedLinkPasswordOptions{}, invalidArgumentsErrorWithDetails("shared link password cannot be empty", flagsErrorDetails("password", "password-prompt", "password-file")) |
| 85 | } |
| 86 | |
| 87 | return sharedLinkPasswordOptions{ |
| 88 | password: password, |
| 89 | set: true, |
| 90 | }, nil |
| 91 | } |
| 92 | |
| 93 | func defaultReadSharedLinkPassword(prompt string, in io.Reader, errOut io.Writer) (string, error) { |
| 94 | if errOut == nil { |
no test coverage detected