• 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

95.35
/cmd/accountcontextparams.go
1
// Copyright 2018 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

19
        "github.com/nats-io/nsc/v2/cmd/store"
20

21
        "github.com/spf13/cobra"
22
)
23

24
type AccountContextParams struct {
25
        Name string
26
}
27

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

2✔
32
func (p *AccountContextParams) SetDefaults(ctx ActionCtx) error {
2✔
33
        config := GetConfig()
34
        if p.Name != "" {
2✔
35
                // if specified, sync the context
2✔
36
                err := config.SetAccountTemp(p.Name)
4✔
37
                if err != nil {
2✔
38
                        return err
2✔
39
                }
4✔
40
                ctx.StoreCtx().Account.Name = p.Name
2✔
41
        } else {
2✔
42
                if config.Account != "" {
2✔
43
                        ctx.StoreCtx().Account.Name = config.Account
2✔
44
                        p.Name = config.Account
4✔
45
                }
2✔
46
        }
2✔
47
        if p.Name != "" {
2✔
48
                return p.setAccount(ctx, p.Name)
49
        }
4✔
50

2✔
51
        return nil
2✔
52
}
53

2✔
54
func (p *AccountContextParams) Edit(ctx ActionCtx) error {
55
        var err error
56
        name, err := PickAccount(ctx.StoreCtx(), p.Name)
2✔
57
        if err != nil {
2✔
58
                return err
2✔
59
        }
4✔
60
        return p.setAccount(ctx, name)
2✔
61
}
2✔
62

2✔
63
func (p *AccountContextParams) Validate(ctx ActionCtx) error {
64
        // default account was not found by get context, so we either we have none or many
65
        if p.Name == "" {
2✔
66
                ctx.CurrentCmd().SilenceUsage = false
2✔
67
                return errors.New("an account is required")
4✔
68
        }
2✔
69
        return nil
2✔
70
}
2✔
71

2✔
72
func (p *AccountContextParams) setAccount(ctx ActionCtx, name string) error {
73
        ac, err := ctx.StoreCtx().Store.ReadAccountClaim(name)
74
        if err != nil && !store.IsNotExist(err) {
2✔
75
                return err
2✔
76
        }
2✔
UNCOV
77
        p.Name = name
×
UNCOV
78
        ctx.StoreCtx().Account.PublicKey = ac.Subject
×
79
        return nil
2✔
80
}
2✔
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