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

nats-io / nsc / 14765656943

30 Apr 2025 10:34PM UTC coverage: 69.949% (-4.2%) from 74.148%
14765656943

Pull #691

github

web-flow
Merge b4ee16f94 into a9c0df586
Pull Request #691: Generate docs

1 of 1 new or added line in 1 file covered. (100.0%)

3680 existing lines in 93 files now uncovered.

12325 of 17620 relevant lines covered (69.95%)

1.66 hits per line

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

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

14
package cmd
15

16
import (
17
        "errors"
18
        "fmt"
19

20
        "github.com/nats-io/nsc/v2/cmd/store"
21
        "github.com/spf13/cobra"
22
)
23

24
type UserContextParams struct {
25
        Name string
26
}
27

28
func (p *UserContextParams) BindFlags(cmd *cobra.Command) {
29
        cmd.Flags().StringVarP(&p.Name, "user", "u", "", "user name")
30
}
2✔
31

2✔
32
func (p *UserContextParams) SetDefaults(ctx ActionCtx) error {
2✔
33
        config := GetConfig()
34
        if config.Operator == "" {
2✔
35
                return fmt.Errorf("no operator set - `%s env --operator <name>`", GetToolName())
2✔
36
        }
2✔
UNCOV
37
        if config.Account == "" {
×
38
                return fmt.Errorf("no account set - `%s env --account <name>`", GetToolName())
×
39
        }
2✔
UNCOV
40
        if p.Name == "" {
×
UNCOV
41
                s, err := config.LoadStore(config.Operator)
×
42
                if err != nil {
4✔
43
                        return err
2✔
44
                }
2✔
UNCOV
45
                names, err := s.ListEntries(store.Accounts, config.Account, store.Users)
×
UNCOV
46
                if err != nil {
×
47
                        return err
2✔
48
                }
2✔
UNCOV
49
                if len(names) == 1 {
×
UNCOV
50
                        p.Name = names[0]
×
51
                }
4✔
52
        }
2✔
53

2✔
54
        return nil
55
}
56

2✔
57
func (p *UserContextParams) Edit(ctx ActionCtx) error {
58
        account := ctx.StoreCtx().Account.Name
UNCOV
59
        if account == "" {
×
60
                config := GetConfig()
×
61
                account = config.Account
×
62
        }
×
UNCOV
63
        var err error
×
UNCOV
64
        p.Name, err = PickUser(ctx.StoreCtx(), account)
×
UNCOV
65
        if err != nil {
×
66
                return err
×
67
        }
68
        return nil
69
}
2✔
70

2✔
71
func (p *UserContextParams) Validate(ctx ActionCtx) error {
2✔
UNCOV
72
        // default account was not found by get context, so we either we have none or many
×
UNCOV
73
        if p.Name == "" {
×
74
                ctx.CurrentCmd().SilenceUsage = false
×
75
                return errors.New("a user is required")
2✔
76
        }
77
        return nil
78
}
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

© 2025 Coveralls, Inc