Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ability to filter devices by prod or non-prod flag #395

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
vkhoroz marked this conversation as resolved.
Show resolved Hide resolved
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,
vkhoroz marked this conversation as resolved.
Show resolved Hide resolved
deviceByTag,
factory,
deviceByGroup,
Expand Down
Loading