Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Following is the current checklist of the implemented schemas and API methods.
| DELETE | `/trackables` | ✅ |
| GET | `/trackables/:trackableID` | ✅ |
| DELETE | `/trackables/:trackableID` | ✅ |
| PUT | `/trackables/:trackableID` | |
| PUT | `/trackables/:trackableID` | |
| GET | `/trackables/:trackableID/fences` | |
| GET | `/trackables/:trackableID/location` | ✅ |
| GET | `/trackables/:trackableID/locations` | |
Expand All @@ -203,9 +203,9 @@ Following is the current checklist of the implemented schemas and API methods.
| POST | `/providers` | ✅ |
| DELETE | `/providers` | ✅ |
| GET | `/providers/:providerID` | ✅ |
| PUT | `/providers/:providerID` | |
| PUT | `/providers/:providerID` | |
| DELETE | `/providers/:providerID` | ✅ |
| PUT | `/providers/:providerID/location` | |
| PUT | `/providers/:providerID/location` | |
| GET | `/providers/:providerID/location` | |
| DELETE | `/providers/:providerID/location` | |
| GET | `/providers/:providerID/fences` | |
Expand Down
2 changes: 2 additions & 0 deletions cmd/omlox-cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Common actions for omlox client:
- omlox sub location_updates
- omlox get trackables -o json > backup.trackables.json
- omlox create trackables < backup.trackables.json
- omlox update trackables < backup.trackables.json

Environment variables:

Expand Down Expand Up @@ -53,6 +54,7 @@ func newRootCmd(out io.Writer, args []string) (*cobra.Command, error) {
newVersionCmd(out),
newGetCmd(*settings, out),
newCreateCmd(*settings, out),
newUpdateCmd(*settings, out),
newDeleteCmd(*settings, out),
newSubCmd(*settings, out),
newGenCmd(),
Expand Down
25 changes: 25 additions & 0 deletions cmd/omlox-cli/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"io"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go/internal/cli"
)

func newUpdateCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Aliases: []string{"set"},
Short: "Update hub resources",
}

cmd.AddCommand(newUpdateTrackablesCmd(settings, out))
cmd.AddCommand(newUpdateProvidersCmd(settings, out))
cmd.AddCommand(newUpdateProvidersLocationsCmd(settings, out))

return cmd
}
79 changes: 79 additions & 0 deletions cmd/omlox-cli/update_providers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"context"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go"
"github.com/wavecomtech/omlox-client-go/internal/cli"
"github.com/wavecomtech/omlox-client-go/internal/cli/resource"
)

const updateProviderHelp = `
This command updates location providers in the Omlox Hub.
`

func newUpdateProvidersCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
var files []string

cmd := &cobra.Command{
Use: "providers",
Aliases: []string{"location_providers"},
Short: "Update location providers in the Hub",
Long: updateProviderHelp,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var in []io.Reader

if len(files) > 0 {
for _, name := range files {
f, err := os.OpenFile(name, os.O_RDONLY, 0444)
if err != nil {
return err
}
defer f.Close()

in = append(in, f)
}
} else {
in = append(in, cmd.InOrStdin())
}

loader := resource.Loader[omlox.LocationProvider]{
Resources: make([]omlox.LocationProvider, 0),
}
for _, r := range in {
if err := loader.LoadJSON(r); err != nil {
return err
}
}

c, err := newOmloxClient(&settings)
if err != nil {
return err
}

for _, p := range loader.Resources {
err := c.Providers.Update(context.Background(), p, p.ID)
if err != nil {
return err
}

fmt.Fprintf(out, "updated: %v %v\n", p.ID, p.Name)
}

return nil
},
}

f := cmd.Flags()
f.StringArrayVarP(&files, "file", "f", []string{}, "The files that contain the location providers to update")

return cmd
}
79 changes: 79 additions & 0 deletions cmd/omlox-cli/update_providers_location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"context"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go"
"github.com/wavecomtech/omlox-client-go/internal/cli"
"github.com/wavecomtech/omlox-client-go/internal/cli/resource"
)

const updateProviderLocationHelp = `
This command updates location providers locations in the Omlox Hub.
`

func newUpdateProvidersLocationsCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
var files []string

cmd := &cobra.Command{
Use: "providers_locations",
Aliases: []string{"location_providers_locations"},
Short: "Update location providers locations in the Hub",
Long: updateProviderLocationHelp,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var in []io.Reader

if len(files) > 0 {
for _, name := range files {
f, err := os.OpenFile(name, os.O_RDONLY, 0444)
if err != nil {
return err
}
defer f.Close()

in = append(in, f)
}
} else {
in = append(in, cmd.InOrStdin())
}

loader := resource.Loader[omlox.Location]{
Resources: make([]omlox.Location, 0),
}
for _, r := range in {
if err := loader.LoadJSON(r); err != nil {
return err
}
}

c, err := newOmloxClient(&settings)
if err != nil {
return err
}

for _, p := range loader.Resources {
err := c.Providers.UpdateLocation(context.Background(), p, p.ProviderID)
if err != nil {
return err
}

fmt.Fprintf(out, "updated: %v location\n", p.ProviderID)
}

return nil
},
}

f := cmd.Flags()
f.StringArrayVarP(&files, "file", "f", []string{}, "The files that contain the location providers locations to update")

return cmd
}
78 changes: 78 additions & 0 deletions cmd/omlox-cli/update_trackables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"context"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go"
"github.com/wavecomtech/omlox-client-go/internal/cli"
"github.com/wavecomtech/omlox-client-go/internal/cli/resource"
)

const updateTrackableHelp = `
This command updates trackables in the Omlox Hub.
`

func newUpdateTrackablesCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
var files []string

cmd := &cobra.Command{
Use: "trackables",
Short: "Update trackables in the Hub",
Long: updateTrackableHelp,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var in []io.Reader

if len(files) > 0 {
for _, name := range files {
f, err := os.OpenFile(name, os.O_RDONLY, 0444)
if err != nil {
return err
}
defer f.Close()

in = append(in, f)
}
} else {
in = append(in, cmd.InOrStdin())
}

loader := resource.Loader[omlox.Trackable]{
Resources: make([]omlox.Trackable, 0),
}
for _, r := range in {
if err := loader.LoadJSON(r); err != nil {
return err
}
}

c, err := newOmloxClient(&settings)
if err != nil {
return err
}

for _, t := range loader.Resources {
err := c.Trackables.Update(context.Background(), t, t.ID)
if err != nil {
return err
}

fmt.Fprintf(out, "updated: %v %v\n", t.ID, t.Name)
}

return nil
},
}

f := cmd.Flags()
f.StringArrayVarP(&files, "file", "f", []string{}, "The files that contain the trackables to update")

return cmd
}
2 changes: 2 additions & 0 deletions docs/cli/omlox.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Common actions for omlox client:
- omlox sub location_updates
- omlox get trackables -o json > backup.trackables.json
- omlox create trackables < backup.trackables.json
- omlox update trackables < backup.trackables.json

Environment variables:

Expand All @@ -35,5 +36,6 @@ Environment variables:
* [omlox gen](omlox_gen.md) - Generate commands
* [omlox get](omlox_get.md) - Get hub resources
* [omlox subscribe](omlox_subscribe.md) - Subscribes to real-time events
* [omlox update](omlox_update.md) - Update hub resources
* [omlox version](omlox_version.md) - Show version information

24 changes: 24 additions & 0 deletions docs/cli/omlox_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## omlox update

Update hub resources

### Options

```
-h, --help help for update
```

### Options inherited from parent commands

```
--addr string omlox hub API endpoint (default "localhost:8081")
--debug enable debug logging
```

### SEE ALSO

* [omlox](omlox.md) - The Omlox Hub CLI tool
* [omlox update providers](omlox_update_providers.md) - Update location providers in the Hub
* [omlox update providers_locations](omlox_update_providers_locations.md) - Update location providers locations in the Hub
* [omlox update trackables](omlox_update_trackables.md) - Update trackables in the Hub

32 changes: 32 additions & 0 deletions docs/cli/omlox_update_providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## omlox update providers

Update location providers in the Hub

### Synopsis


This command updates location providers in the Omlox Hub.


```
omlox update providers [flags]
```

### Options

```
-f, --file stringArray The files that contain the location providers to update
-h, --help help for providers
```

### Options inherited from parent commands

```
--addr string omlox hub API endpoint (default "localhost:8081")
--debug enable debug logging
```

### SEE ALSO

* [omlox update](omlox_update.md) - Update hub resources

Loading
Loading