• 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

0.0
/internal/cli/workflows/flags.go
1
// Copyright 2023 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 workflows
16

17
import (
18
        "strconv"
19
        "strings"
20

21
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
22
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/log"
23
)
24

25
var GlobalFlagsToArgs = map[string]string{
26
        flag.Profile:      "1",
27
        flag.ProfileShort: "1",
28
        flag.Debug:        "0",
29
        flag.DebugShort:   "0",
30
}
31

32
func shouldRemoveFlagAndArgs(flags map[string]string, arg string) (int, error) {
×
33
        trimmedArg := strings.TrimLeft(arg, "-")
×
34

×
35
        flagArgsCount := flags[trimmedArg]
×
36
        if flagArgsCount == "" {
×
37
                flagArgsCount = GlobalFlagsToArgs[trimmedArg]
×
38
        }
×
39

40
        if flagArgsCount != "" {
×
41
                flagArgsCountValue, err := strconv.Atoi(flagArgsCount)
×
42
                if err != nil {
×
43
                        return -1, err
×
44
                }
×
45
                return flagArgsCountValue, nil
×
46
        }
47

48
        return -1, nil
×
49
}
50

51
func RemoveFlagsAndArgs(flagsToBeRemoved map[string]string, argsToBeRemoved map[string]bool, args []string) ([]string, error) {
×
52
        var newArgs []string
×
53
        for i := 0; i < len(args); i++ {
×
54
                arg := args[i]
×
55

×
56
                // remove global flags
×
57
                flagArgsCount, err := shouldRemoveFlagAndArgs(flagsToBeRemoved, arg)
×
58
                if err != nil {
×
59
                        _, _ = log.Debugf("Error while removing flags and arg(s): %s\n", err)
×
60
                        return nil, err
×
61
                }
×
62

63
                if flagArgsCount >= 0 {
×
64
                        _, _ = log.Debugf("Skipped flag %s and %d arg(s)\n", args[i], flagArgsCount)
×
65
                        i += flagArgsCount // skip the args after flag
×
66
                        continue
×
67
                }
68

69
                // remove args
70
                if argsToBeRemoved[arg] {
×
71
                        _, _ = log.Debugf("Skipped arg %s\n", args[i])
×
72
                        continue
×
73
                }
74

75
                newArgs = append(newArgs, arg)
×
76
        }
77

78
        _, _ = log.Debugf("Removing 3 first terms in %s \n", newArgs)
×
79
        return newArgs[3:], nil
×
80
}
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