Skip to content

Commit

Permalink
Feature: ability to filter devices by prod or non-prod flag
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Khoroz <[email protected]>
  • Loading branch information
vkhoroz committed Apr 17, 2024
1 parent af8a264 commit 846d49c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 13 additions & 4 deletions client/foundries.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,25 @@ func (a *Api) DeviceGet(factory, device string) (*Device, error) {
}

func (a *Api) DeviceList(
mine bool, matchTag, byFactory, byGroup, nameIlike, uuid, byTarget, sortBy string, page, limit uint64,
mine, prod, nonProd bool, matchTag, byFactory, byGroup, nameIlike, uuid, byTarget, sortBy string, page, limit uint64,
) (*DeviceList, error) {
mineInt := 0
var (
mineInt int
prodStr string
)
if mine {
mineInt = 1
}
switch {
case prod:
prodStr = "1"
case nonProd:
prodStr = "0"
}
url := a.serverUrl + "/ota/devices/?"
url += fmt.Sprintf(
"mine=%d&match_tag=%s&name_ilike=%s&factory=%s&uuid=%s&group=%s&target_name=%s&sortby=%s&page=%d&limit=%d",
mineInt, matchTag, nameIlike, byFactory, uuid, byGroup, byTarget, sortBy, page, limit)
"mine=%d&prod=%s&match_tag=%s&name_ilike=%s&factory=%s&uuid=%s&group=%s&target_name=%s&sortby=%s&page=%d&limit=%d",
mineInt, prodStr, matchTag, nameIlike, byFactory, uuid, byGroup, byTarget, sortBy, page, limit)
logrus.Debugf("DeviceList with url: %s", url)
return a.DeviceListCont(url)
}
Expand Down
7 changes: 7 additions & 0 deletions subcommands/devices/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

var (
deviceMine bool
deviceOnlyProd bool
deviceOnlyNonProd bool
deviceByTag string
deviceByTarget string
deviceByGroup string
Expand Down Expand Up @@ -142,6 +144,8 @@ func init() {
}
cmd.AddCommand(listCmd)
listCmd.Flags().BoolVarP(&deviceMine, "just-mine", "", false, "Only include devices owned by you")
listCmd.Flags().BoolVarP(&deviceOnlyProd, "only-prod", "", false, "Only include production devices")
listCmd.Flags().BoolVarP(&deviceOnlyNonProd, "only-non-prod", "", false, "Only include non-production devices")
listCmd.Flags().StringVarP(&deviceByTag, "by-tag", "", "", "Only list devices configured with the given tag")
listCmd.Flags().StringVarP(&deviceByTarget, "by-target", "", "", "Only list devices updated to the given target name")
listCmd.Flags().StringVarP(&deviceByGroup, "by-group", "g", "", "Only list devices belonging to this group (factory is mandatory)")
Expand All @@ -151,6 +155,7 @@ func init() {
addPaginationFlags(listCmd)
addSortFlag(listCmd, "sort-by-name", "", "Sort by name (asc, desc); default sort is by owner and name")
addSortFlag(listCmd, "sort-by-last-seen", "", "Sort by last-seen (asc, desc); default sort is by owner and name")
listCmd.MarkFlagsMutuallyExclusive("only-prod", "only-non-prod")
listCmd.MarkFlagsMutuallyExclusive("sort-by-name", "sort-by-last-seen")
}

Expand Down Expand Up @@ -221,6 +226,8 @@ func doList(cmd *cobra.Command, args []string) {
}
dl, err := api.DeviceList(
deviceMine,
deviceOnlyProd,
deviceOnlyNonProd,
deviceByTag,
factory,
deviceByGroup,
Expand Down

0 comments on commit 846d49c

Please sign in to comment.