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

mongodb / mongodb-atlas-cli / 16670272475

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

Pull #4071

github

fmenezes
lint
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

68.29
/internal/cli/api/flags.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
        "errors"
19
        "fmt"
20
        "strings"
21

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

26
var (
27
        errUnsupportedType   = errors.New("unsupported parameter type")
28
        errFlagAlreadyExists = errors.New("parameter already exists")
29
)
30

31
func addFlag(cmd *cobra.Command, parameter api.Parameter) error {
1✔
32
        name := parameter.Name
1✔
33

1✔
34
        if cmd.Flag(name) != nil {
1✔
35
                // this should never happen, the api command generation tool should cover this
×
36
                return fmt.Errorf("%w: %s", errFlagAlreadyExists, name)
×
37
        }
×
38

39
        shortDescription := flagDescription(parameter.Description)
1✔
40

1✔
41
        if parameter.Type.IsArray {
2✔
42
                switch parameter.Type.Type {
1✔
43
                case api.TypeString:
1✔
44
                        cmd.Flags().StringArrayP(name, parameter.Short, nil, shortDescription)
1✔
45
                case api.TypeInt:
×
46
                        cmd.Flags().Int32SliceP(name, parameter.Short, nil, shortDescription)
×
47
                case api.TypeBool:
×
48
                        cmd.Flags().BoolSliceP(name, parameter.Short, nil, shortDescription)
×
49
                default:
×
50
                        return fmt.Errorf("%w: %s", errUnsupportedType, parameter.Type.Type)
×
51
                }
52
        } else {
1✔
53
                switch parameter.Type.Type {
1✔
54
                case api.TypeString:
1✔
55
                        cmd.Flags().StringP(name, parameter.Short, "", shortDescription)
1✔
56
                case api.TypeInt:
1✔
57
                        cmd.Flags().IntP(name, parameter.Short, 0, shortDescription)
1✔
58
                case api.TypeBool:
1✔
59
                        cmd.Flags().BoolP(name, parameter.Short, false, shortDescription)
1✔
60
                default:
×
61
                        return fmt.Errorf("%w: %s", errUnsupportedType, parameter.Type.Type)
×
62
                }
63
        }
64

65
        if parameter.Required {
2✔
66
                if err := cmd.MarkFlagRequired(name); err != nil {
1✔
67
                        return err
×
68
                }
×
69
        }
70

71
        return nil
1✔
72
}
73

74
func flagDescription(description string) string {
1✔
75
        shortDescription, _ := splitShortAndLongDescription(description)
1✔
76
        if len(shortDescription) > 0 {
2✔
77
                shortDescription = strings.ToLower(shortDescription[:1]) + shortDescription[1:]
1✔
78
        }
1✔
79
        shortDescription = strings.TrimSuffix(shortDescription, ".")
1✔
80
        return shortDescription
1✔
81
}
82

83
type FlagValueProvider interface {
84
        ValueForFlag(flagName string) (*string, error)
85
}
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