Skip to content

Commit

Permalink
feat: Make list a default command operation
Browse files Browse the repository at this point in the history
Make list default command operation for all commands, but still keep the
list as an available operation
Example list all devices could be called in two ways:
> edgex-cli device
> edgex-cli device list

Closes: edgexfoundry#336

Signed-off-by: Diana Atanasova <[email protected]>
  • Loading branch information
difince committed Jan 13, 2021
1 parent 4e4b63e commit 582081a
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 50 deletions.
10 changes: 4 additions & 6 deletions cmd/addressable/addressable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package addressable

import (
// addsubscription "github.com/edgexfoundry/edgex-cli/cmd/subscription/add"
listaddressable "github.com/edgexfoundry/edgex-cli/cmd/addressable/list"
// rmsubscription "github.com/edgexfoundry/edgex-cli/cmd/subscription/rm"
list "github.com/edgexfoundry/edgex-cli/cmd/addressable/list"

"github.com/spf13/cobra"
)

Expand All @@ -27,9 +26,8 @@ func NewCommand() *cobra.Command {
Use: "addressable",
Short: "Addressable command",
Long: `Actions related to addressable.`,
RunE: list.Handler,
}
cmd.AddCommand(listaddressable.NewCommand())
// cmd.AddCommand(rmsubscription.NewCommand())
// cmd.AddCommand(listsubscription.NewCommand())
cmd.AddCommand(list.NewCommand())
return cmd
}
6 changes: 4 additions & 2 deletions cmd/addressable/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func NewCommand() *cobra.Command {
Use: "list",
Short: "A list of all addressable",
Long: `Return all addressable sorted by id.`,
RunE: listHandler,
RunE: Handler,
}
return cmd
}
func listHandler(cmd *cobra.Command, args []string) (err error) {

//Handler list all Addressable and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
url := config.Conf.Clients["Metadata"].Url() + clients.ApiAddressableRoute
var addr []models.Addressable
err = request.Get(cmd.Context(), url, &addr)
Expand Down
1 change: 1 addition & 0 deletions cmd/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewCommand() *cobra.Command {
Use: "command",
Short: "`Command` command",
Long: `Actions related to commands.`,
RunE: list.Handler,
}
cmd.AddCommand(list.NewCommand())
cmd.AddCommand(get.NewCommand())
Expand Down
5 changes: 3 additions & 2 deletions cmd/command/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ func NewCommand() *cobra.Command {
Use: "list",
Short: "A list of device supported commands",
Long: "Return a list of all device `commands`",
RunE: listHandler,
RunE: Handler,
}
cmd.Flags().StringVarP(&device, "device", "d", "", "List commands associated with device specified by name")
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Commands and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
var responses []models.CommandResponse
if device != "" {
responses, err = getCommandsByDeviceName(cmd.Context(), device)
Expand Down
4 changes: 2 additions & 2 deletions cmd/device/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewCommand() *cobra.Command {
Use: "add",
Short: "Add devices",
Long: `Create devices described in a given JSON file or use the interactive mode with additional flags.`,
RunE: deviceHandler,
RunE: Handler,
}
cmd.Flags().BoolVarP(&interactiveMode, editor.InteractiveModeLabel, "i", false, "Open a default editor to customize the Event information")
cmd.Flags().StringVarP(&name, "name", "n", "", "Name")
Expand All @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command {
return cmd
}

func deviceHandler(cmd *cobra.Command, args []string) error {
func Handler(cmd *cobra.Command, args []string) error {
if interactiveMode && file != "" {
return errors.New("you could work with interactive mode or file, but not with both")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewCommand() *cobra.Command {
Use: "device",
Short: "Device command",
Long: `Actions related to devices.`,
RunE: list.Handler,
}
cmd.AddCommand(rm.NewCommand())
cmd.AddCommand(list.NewCommand())
Expand Down
5 changes: 3 additions & 2 deletions cmd/device/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ func NewCommand() *cobra.Command {
Use: "list",
Short: "A list of all devices",
Long: `Return all devices sorted by id.`,
RunE: listHandler,
RunE: Handler,
}
cmd.Flags().StringVarP(&name, "name", "n", "", "Returns Device matching the given name")
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Devices and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
url := config.Conf.Clients["Metadata"].Url() + clients.ApiDeviceRoute
mdc := metadata.NewDeviceClient(
local.New(url),
Expand Down
1 change: 1 addition & 0 deletions cmd/deviceservice/deviceservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sensors, actuators, and other IoT objects through protocols native to the IoT ob
The DS Layer converts the data produced and communicated by the IoT object, into a
common EdgeX Foundry data structure, and sends that converted data into the Core Services
layer, and to other microservices in other layers of EdgeX Foundry.`,
RunE: list.Handler,
}
cmd.AddCommand(rm.NewCommand())
cmd.AddCommand(list.NewCommand())
Expand Down
5 changes: 3 additions & 2 deletions cmd/deviceservice/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ func NewCommand() *cobra.Command {
Use: "list [<id>]\",",
Short: "Lists existing devices services",
Long: `Return the list of current device services or Device Service matching the given id`,
RunE: listHandler,
RunE: Handler,
}
cmd.Flags().StringVarP(&name, "name", "n", "", "Returns Device Service matching the given name")
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list DeviceServices and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
url := config.Conf.Clients["Metadata"].Url() + clients.ApiDeviceServiceRoute
var deviceServices []models.DeviceService
var ds models.DeviceService
Expand Down
13 changes: 7 additions & 6 deletions cmd/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package event

import (
addevent "github.com/edgexfoundry/edgex-cli/cmd/event/add"
add "github.com/edgexfoundry/edgex-cli/cmd/event/add"
"github.com/edgexfoundry/edgex-cli/cmd/event/count"
listevent "github.com/edgexfoundry/edgex-cli/cmd/event/list"
rmevent "github.com/edgexfoundry/edgex-cli/cmd/event/rm"
list "github.com/edgexfoundry/edgex-cli/cmd/event/list"
rm "github.com/edgexfoundry/edgex-cli/cmd/event/rm"
"github.com/edgexfoundry/edgex-cli/cmd/event/scrub"

"github.com/spf13/cobra"
Expand All @@ -30,10 +30,11 @@ func NewCommand() *cobra.Command {
Use: "event",
Short: "Event command",
Long: `Actions related to device-generated events.`,
RunE: list.Handler,
}
cmd.AddCommand(rmevent.NewCommand())
cmd.AddCommand(addevent.NewCommand())
cmd.AddCommand(listevent.NewCommand())
cmd.AddCommand(rm.NewCommand())
cmd.AddCommand(add.NewCommand())
cmd.AddCommand(list.NewCommand())
cmd.AddCommand(count.NewCommand())
cmd.AddCommand(scrub.NewCommand())
return cmd
Expand Down
5 changes: 3 additions & 2 deletions cmd/event/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ func NewCommand() *cobra.Command {
Short: "A list of Events",
Long: `Return list of Events.`,
Args: cobra.MaximumNArgs(1),
RunE: listHandler,
RunE: Handler,
}
cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit number of results")
cmd.Flags().StringVarP(&device, "device", "d", "", "Events generated by specific device with given name.")
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Events and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
client := coredata.NewEventClient(
local.New(config.Conf.Clients["CoreData"].Url() + clients.ApiEventRoute),
)
Expand Down
1 change: 1 addition & 0 deletions cmd/interval/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewCommand() *cobra.Command {
Use: "interval",
Short: "Interval command",
Long: `Actions related to intervals (scheduler).`,
RunE: list.Handler,
}
cmd.AddCommand(add.NewCommand())
cmd.AddCommand(rm.NewCommand())
Expand Down
5 changes: 3 additions & 2 deletions cmd/interval/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const intervalTemplate = "Interval ID\tName\tStart\tEnd\tFrequency\tCron\tRunOnc
"{{.ID}}\t{{.Name}}\t{{.Start}}\t{{.End}}\t{{.Frequency}}\t{{.Cron}}\t{{.RunOnce}}\n" +
"{{end}}"

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Intervals and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
client := scheduler.NewIntervalClient(
local.New(config.Conf.Clients["Scheduler"].Url() + clients.ApiIntervalRoute),
)
Expand Down Expand Up @@ -66,7 +67,7 @@ func NewCommand() *cobra.Command {
Short: "A list of all intervals",
Long: `Return a list of all intervals or retrieve an interval by id`,
Args: cobra.MaximumNArgs(1),
RunE: listHandler,
RunE: Handler,
}
return cmd
}
5 changes: 3 additions & 2 deletions cmd/notification/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewCommand() *cobra.Command {
Short: "A list of all notifications",
Long: `Return a list of all notifications filtered by slug/sender/labels/start/end/new and limited by limit. Defaults to new notifications.`,
Args: cobra.MaximumNArgs(3),
RunE: listHandler,
RunE: Handler,
FParseErrWhitelist: cobra.FParseErrWhitelist{},
}

Expand All @@ -64,7 +64,8 @@ func NewCommand() *cobra.Command {
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Notifications and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
var url string
multi := true
url = config.Conf.Clients["Notification"].Url() + clients.ApiNotificationRoute
Expand Down
13 changes: 7 additions & 6 deletions cmd/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package notification

import (
addnotification "github.com/edgexfoundry/edgex-cli/cmd/notification/add"
listnotification "github.com/edgexfoundry/edgex-cli/cmd/notification/list"
rmdnotification "github.com/edgexfoundry/edgex-cli/cmd/notification/rm"
add "github.com/edgexfoundry/edgex-cli/cmd/notification/add"
list "github.com/edgexfoundry/edgex-cli/cmd/notification/list"
rm "github.com/edgexfoundry/edgex-cli/cmd/notification/rm"

"github.com/spf13/cobra"
)
Expand All @@ -27,9 +27,10 @@ func NewCommand() *cobra.Command {
Use: "notification",
Short: "Notification command",
Long: `Actions related to notifications.`,
RunE: list.Handler,
}
cmd.AddCommand(rmdnotification.NewCommand())
cmd.AddCommand(addnotification.NewCommand())
cmd.AddCommand(listnotification.NewCommand())
cmd.AddCommand(rm.NewCommand())
cmd.AddCommand(add.NewCommand())
cmd.AddCommand(list.NewCommand())
return cmd
}
5 changes: 3 additions & 2 deletions cmd/profile/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ func NewCommand() *cobra.Command {
Use: "list",
Short: "Returns a list of device profiles",
Long: `Returns the list of device profiles currently in the core-metadata database.`,
RunE: listHandler,
RunE: Handler,
}
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Profiles and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
url := config.Conf.Clients["Metadata"].Url()
mdc := metadata.NewDeviceProfileClient(
local.New(url + clients.ApiDeviceProfileRoute),
Expand Down
1 change: 1 addition & 0 deletions cmd/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewCommand() *cobra.Command {
Device profiles define general characteristics about devices,
the data they provide, and how to command them.`,
RunE: list.Handler,
}

cmd.AddCommand(rm.NewCommand())
Expand Down
5 changes: 3 additions & 2 deletions cmd/reading/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ func NewCommand() *cobra.Command {
Short: "A list of readings across devices or pertaining to a specified device",
Long: `Return list of readings across devices or pertaining to a specified device.`,
Args: cobra.MaximumNArgs(1),
RunE: listHandler,
RunE: Handler,
}
cmd.Flags().StringVarP(&device, "device", "d", "", "Readings generated by specific device with given name.")
cmd.Flags().Int32VarP(&limit, "limit", "l", 50, "Limit number of results")
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Readings and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
var url string
if device != "" {
limitUrl := strconv.FormatInt(int64(limit), 10)
Expand Down
5 changes: 3 additions & 2 deletions cmd/reading/reading.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package reading

import (
"github.com/edgexfoundry/edgex-cli/cmd/reading/count"
listevent "github.com/edgexfoundry/edgex-cli/cmd/reading/list"
list "github.com/edgexfoundry/edgex-cli/cmd/reading/list"

"github.com/spf13/cobra"
)
Expand All @@ -27,8 +27,9 @@ func NewCommand() *cobra.Command {
Use: "reading",
Short: "Reading command",
Long: `Actions related to device-generated readings.`,
RunE: list.Handler,
}
cmd.AddCommand(listevent.NewCommand())
cmd.AddCommand(list.NewCommand())
cmd.AddCommand(count.NewCommand())
return cmd
}
5 changes: 3 additions & 2 deletions cmd/subscription/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ func NewCommand() *cobra.Command {
Use: "list",
Short: "A list of all subscriptions",
Long: `Return all Subscriptions`,
RunE: listHandler,
RunE: Handler,
}
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Subscriptions and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
url := config.Conf.Clients["Notification"].Url() + clients.ApiSubscriptionRoute
var subscriptions []models.Subscription
err = request.Get(cmd.Context(), url, &subscriptions)
Expand Down
13 changes: 7 additions & 6 deletions cmd/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package subscription

import (
addsubscription "github.com/edgexfoundry/edgex-cli/cmd/subscription/add"
listsubscription "github.com/edgexfoundry/edgex-cli/cmd/subscription/list"
rmsubscription "github.com/edgexfoundry/edgex-cli/cmd/subscription/rm"
add "github.com/edgexfoundry/edgex-cli/cmd/subscription/add"
list "github.com/edgexfoundry/edgex-cli/cmd/subscription/list"
rm "github.com/edgexfoundry/edgex-cli/cmd/subscription/rm"

"github.com/spf13/cobra"
)
Expand All @@ -28,9 +28,10 @@ func NewCommand() *cobra.Command {
Use: "subscription",
Short: "Subscription command",
Long: `Actions related to subscriptions.`,
RunE: list.Handler,
}
cmd.AddCommand(addsubscription.NewCommand())
cmd.AddCommand(rmsubscription.NewCommand())
cmd.AddCommand(listsubscription.NewCommand())
cmd.AddCommand(add.NewCommand())
cmd.AddCommand(rm.NewCommand())
cmd.AddCommand(list.NewCommand())
return cmd
}
5 changes: 3 additions & 2 deletions cmd/watcher/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ func NewCommand() *cobra.Command {
Short: "A list of watchers",
Long: `Return a list of watchers or retrieve a watcher by id`,
Args: cobra.MaximumNArgs(1),
RunE: listHandler,
RunE: Handler,
}
return cmd
}

func listHandler(cmd *cobra.Command, args []string) (err error) {
//Handler list Watchers and display them
func Handler(cmd *cobra.Command, args []string) (err error) {
client := metadata.NewProvisionWatcherClient(
local.New(config.Conf.Clients["Metadata"].Url() + clients.ApiProvisionWatcherRoute),
)
Expand Down
1 change: 1 addition & 0 deletions cmd/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewCommand() *cobra.Command {
Use: "watcher",
Short: "Watcher command",
Long: `Actions related to watchers.`,
RunE: list.Handler,
}
cmd.AddCommand(list.NewCommand())
cmd.AddCommand(rm.NewCommand())
Expand Down

0 comments on commit 582081a

Please sign in to comment.