• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb / mongodb-atlas-cli / 16670223591

01 Aug 2025 08:25AM UTC coverage: 57.953% (-7.1%) from 65.017%
16670223591

Pull #4071

github

fmenezes
chore: remove unit tag from tests
Pull Request #4071: chore: remove unit tag from tests

23613 of 40745 relevant lines covered (57.95%)

2.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/internal/cli/api/command_request.go
1
// Copyright 2024 MongoDB Inc
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package api
16

17
import (
18
        "io"
19

20
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/api"
21
        shared_api "github.com/mongodb/mongodb-atlas-cli/atlascli/tools/shared/api"
22
        "github.com/spf13/cobra"
23
        "github.com/spf13/pflag"
24
)
25

26
func NewCommandRequestFromCobraCommand(cobraCommand *cobra.Command, apiCommand shared_api.Command, content io.Reader, format string, version shared_api.Version) (*api.CommandRequest, error) {
1✔
27
        return &api.CommandRequest{
1✔
28
                Command:    apiCommand,
1✔
29
                Content:    content,
1✔
30
                Format:     format,
1✔
31
                Parameters: cobraFlagsToRequestParameters(cobraCommand),
1✔
32
                Version:    version,
1✔
33
        }, nil
1✔
34
}
1✔
35

36
func cobraFlagsToRequestParameters(cobraCommand *cobra.Command) map[string][]string {
1✔
37
        parameters := make(map[string][]string)
1✔
38
        var flagsToIgnore = map[string]struct{}{
1✔
39
                "file":    {},
1✔
40
                "version": {},
1✔
41
        }
1✔
42

1✔
43
        cobraCommand.LocalFlags().VisitAll(func(flag *pflag.Flag) {
2✔
44
                if _, ignoreFlag := flagsToIgnore[flag.Name]; ignoreFlag {
2✔
45
                        return
1✔
46
                }
1✔
47

48
                // If the flag has not been set, don't set the value
49
                // Doing this would cause the request to contain all default values and might set not required values to not desired values
50
                if !flag.Changed {
2✔
51
                        return
1✔
52
                }
1✔
53

54
                if values, ok := flag.Value.(pflag.SliceValue); ok {
1✔
55
                        parameters[flag.Name] = values.GetSlice()
×
56
                } else {
1✔
57
                        parameters[flag.Name] = []string{flag.Value.String()}
1✔
58
                }
1✔
59
        })
60

61
        return parameters
1✔
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc