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

mongodb / mongodb-atlas-cli / 17463390076

04 Sep 2025 12:11PM UTC coverage: 64.106% (-0.05%) from 64.155%
17463390076

push

github

web-flow
fix: upgrades core dep and implements (#4187)

2 of 4 new or added lines in 4 files covered. (50.0%)

18 existing lines in 1 file now uncovered.

26202 of 40873 relevant lines covered (64.11%)

0.79 hits per line

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

25.93
/internal/cli/processes/process_autocomplete.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 processes
16

17
import (
18
        "context"
19
        "fmt"
20
        "sort"
21
        "strings"
22

23
        "github.com/mongodb/atlas-cli-core/config"
24
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
27
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/validate"
28
        "github.com/spf13/cobra"
29
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312006/admin"
30
)
31

32
type AutoCompleteOpts struct {
33
        cli.ProjectOpts
34
        store ProcessLister
35
}
36

37
func (opts *AutoCompleteOpts) AutocompleteProcesses() cli.AutoFunc {
1✔
38
        return func(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
1✔
39
                if err := opts.parseFlags(cmd); err != nil {
×
40
                        cobra.CompErrorln(fmt.Sprintf("failed to parse flags: %v", err))
×
41
                        return nil, cobra.ShellCompDirectiveError
×
42
                }
×
43

44
                if err := validate.Credentials(); err != nil {
×
45
                        cobra.CompErrorln("no credentials")
×
46
                        return nil, cobra.ShellCompDirectiveError
×
47
                }
×
48
                if err := opts.ValidateProjectID(); err != nil {
×
49
                        cobra.CompErrorln("no project ID")
×
50
                        return nil, cobra.ShellCompDirectiveError
×
51
                }
×
52
                if err := opts.initStore(cmd.Context()); err != nil {
×
53
                        cobra.CompErrorln("store error: " + err.Error())
×
54
                        return nil, cobra.ShellCompDirectiveError
×
55
                }
×
56
                suggestions, err := opts.processSuggestion(toComplete)
×
57
                if err != nil {
×
58
                        cobra.CompErrorln("error fetching: " + err.Error())
×
59
                        return nil, cobra.ShellCompDirectiveError
×
60
                }
×
61
                return suggestions, cobra.ShellCompDirectiveDefault
×
62
        }
63
}
64

65
func (opts *AutoCompleteOpts) processSuggestion(toComplete string) ([]string, error) {
1✔
66
        processesList := &atlasv2.ListAtlasProcessesApiParams{
1✔
67
                GroupId: opts.ConfigProjectID(),
1✔
68
        }
1✔
69
        result, err := opts.store.Processes(processesList)
1✔
70
        if err != nil {
1✔
71
                return nil, err
×
72
        }
×
73
        suggestion := make([]string, 0, len(result.GetResults()))
1✔
74
        for _, p := range result.GetResults() {
2✔
75
                if !strings.HasPrefix(p.GetId(), toComplete) {
1✔
76
                        continue
×
77
                }
78
                suggestion = append(suggestion, p.GetId())
1✔
79
        }
80
        sort.Strings(suggestion)
1✔
81
        return suggestion, nil
1✔
82
}
83

84
func (opts *AutoCompleteOpts) initStore(ctx context.Context) error {
×
85
        var err error
×
86
        opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
87
        return err
×
88
}
×
89

90
func (opts *AutoCompleteOpts) parseFlags(cmd *cobra.Command) error {
×
91
        profile := cmd.Flag(flag.Profile).Value.String()
×
92

×
NEW
93
        if err := config.InitProfile(profile); err != nil {
×
94
                return err
×
95
        }
×
96

97
        if project := cmd.Flag(flag.ProjectID).Value.String(); project != "" {
×
98
                opts.ProjectID = project
×
99
        }
×
100

101
        return nil
×
102
}
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