Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package options |
| 8 | |
| 9 | // ListDatabasesOptions represents all possible options for a listDatabases command. |
| 10 | type ListDatabasesOptions struct { |
| 11 | NameOnly *bool // If true, only the database names will be returned. |
| 12 | } |
| 13 | |
| 14 | // ListDatabases creates a new *ListDatabasesOptions |
| 15 | func ListDatabases() *ListDatabasesOptions { |
| 16 | return &ListDatabasesOptions{} |
| 17 | } |
| 18 | |
| 19 | // SetNameOnly specifies whether to return only the database names. |
| 20 | func (ld *ListDatabasesOptions) SetNameOnly(b bool) *ListDatabasesOptions { |
| 21 | ld.NameOnly = &b |
| 22 | return ld |
| 23 | } |
| 24 | |
| 25 | // MergeListDatabasesOptions combines the given *ListDatabasesOptions into a single *ListDatabasesOptions in a last one |
| 26 | // wins fashion. |
| 27 | func MergeListDatabasesOptions(opts ...*ListDatabasesOptions) *ListDatabasesOptions { |
| 28 | ld := ListDatabases() |
| 29 | for _, opt := range opts { |
| 30 | if opts == nil { |
| 31 | continue |
| 32 | } |
| 33 | if opt.NameOnly != nil { |
| 34 | ld.NameOnly = opt.NameOnly |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return ld |
| 39 | } |