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

mendersoftware / mender-cli / 1779499080

22 Apr 2025 10:11AM UTC coverage: 1.737% (-30.1%) from 31.802%
1779499080

push

gitlab-ci

web-flow
Merge pull request #277 from alfrunes/MEN-7794

MEN-7794: Add support for pagination when listing devices

28 of 82 new or added lines in 4 files covered. (34.15%)

770 existing lines in 17 files now uncovered.

45 of 2590 relevant lines covered (1.74%)

0.04 hits per line

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

0.0
/cmd/devices_list.go
1
// Copyright 2023 Northern.tech AS
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
package cmd
15

16
import (
17
        "errors"
18

19
        "github.com/spf13/cobra"
20
        "github.com/spf13/viper"
21

22
        "github.com/mendersoftware/mender-cli/client/devices"
23
)
24

25
var devicesListCmd = &cobra.Command{
26
        Use:   "list",
27
        Short: "Get a list of devices from the Mender server.",
UNCOV
28
        Run: func(c *cobra.Command, args []string) {
×
UNCOV
29
                cmd, err := NewDevicesListCmd(c, args)
×
UNCOV
30
                CheckErr(err)
×
UNCOV
31
                CheckErr(cmd.Run())
×
UNCOV
32
        },
×
33
}
34

35
const (
36
        argRawMode = "raw"
37
        argPerPage = "per-page"
38
        argPage    = "page"
39
)
40

UNCOV
41
func init() {
×
UNCOV
42
        devicesListCmd.Flags().IntP(argDetailLevel, "d", 0, "devices list detail level [0..3]")
×
NEW
43
        devicesListCmd.Flags().IntP(argPerPage, "N", 20, "Number of results to display")
×
NEW
44
        devicesListCmd.Flags().IntP(argPage, "P", 1, "Page number to return")
×
UNCOV
45
        devicesListCmd.Flags().BoolP(
×
UNCOV
46
                argRawMode,
×
UNCOV
47
                "r",
×
UNCOV
48
                false,
×
UNCOV
49
                "devices list raw mode (json from mender server)")
×
UNCOV
50
}
×
51

52
type DevicesListCmd struct {
53
        server        string
54
        skipVerify    bool
55
        token         string
56
        detailLevel   int
57
        rawMode       bool
58
        page, perPage int
59
}
60

UNCOV
61
func NewDevicesListCmd(cmd *cobra.Command, args []string) (*DevicesListCmd, error) {
×
UNCOV
62
        server := viper.GetString(argRootServer)
×
UNCOV
63
        if server == "" {
×
64
                return nil, errors.New("No server")
×
65
        }
×
66

NEW
67
        flags := cmd.Flags()
×
NEW
68

×
NEW
69
        skipVerify, err := flags.GetBool(argRootSkipVerify)
×
NEW
70
        if err != nil {
×
NEW
71
                return nil, err
×
NEW
72
        }
×
73

NEW
74
        detailLevel, err := flags.GetInt(argDetailLevel)
×
NEW
75
        if err != nil {
×
NEW
76
                return nil, err
×
NEW
77
        }
×
78

NEW
79
        rawMode, err := flags.GetBool(argRawMode)
×
80
        if err != nil {
×
81
                return nil, err
×
82
        }
×
83

NEW
84
        perPage, err := flags.GetInt(argPerPage)
×
UNCOV
85
        if err != nil {
×
86
                return nil, err
×
87
        }
×
88

NEW
89
        page, err := flags.GetInt(argPage)
×
UNCOV
90
        if err != nil {
×
91
                return nil, err
×
92
        }
×
93

UNCOV
94
        token, err := getAuthToken(cmd)
×
UNCOV
95
        if err != nil {
×
96
                return nil, err
×
97
        }
×
98

UNCOV
99
        return &DevicesListCmd{
×
UNCOV
100
                server:      server,
×
UNCOV
101
                token:       token,
×
UNCOV
102
                skipVerify:  skipVerify,
×
UNCOV
103
                detailLevel: detailLevel,
×
UNCOV
104
                rawMode:     rawMode,
×
NEW
105
                perPage:     perPage,
×
NEW
106
                page:        page,
×
UNCOV
107
        }, nil
×
108
}
109

UNCOV
110
func (c *DevicesListCmd) Run() error {
×
UNCOV
111

×
UNCOV
112
        client := devices.NewClient(c.server, c.skipVerify)
×
NEW
113
        return client.ListDevices(c.token, c.detailLevel, c.perPage, c.page, c.rawMode)
×
UNCOV
114
}
×
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