Skip to content

Commit 05f124a

Browse files
committed
fix thing create - improve flags
1 parent 18dfa27 commit 05f124a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

cli/thing/create.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
var createFlags struct {
1111
name string
12-
device string
12+
deviceID string
1313
template string
14-
clone string
14+
cloneID string
1515
}
1616

1717
func initCreateCommand() *cobra.Command {
@@ -22,8 +22,8 @@ func initCreateCommand() *cobra.Command {
2222
RunE: runCreateCommand,
2323
}
2424
createCommand.Flags().StringVarP(&createFlags.name, "name", "n", "", "Thing name")
25-
createCommand.Flags().StringVarP(&createFlags.device, "device", "d", "", "ID of Device to bind to the new thing")
26-
createCommand.Flags().StringVarP(&createFlags.clone, "clone", "c", "", "ID of Thing to be cloned")
25+
createCommand.Flags().StringVarP(&createFlags.deviceID, "device-id", "d", "", "ID of Device to bind to the new thing")
26+
createCommand.Flags().StringVarP(&createFlags.cloneID, "clone-id", "c", "", "ID of Thing to be cloned")
2727
createCommand.Flags().StringVarP(&createFlags.template, "template", "t", "", "File containing a thing template")
2828
createCommand.MarkFlagRequired("name")
2929
return createCommand
@@ -34,9 +34,9 @@ func runCreateCommand(cmd *cobra.Command, args []string) error {
3434

3535
params := &thing.CreateParams{
3636
Name: createFlags.name,
37-
Device: createFlags.device,
37+
DeviceID: createFlags.deviceID,
3838
Template: createFlags.template,
39-
Clone: createFlags.clone,
39+
CloneID: createFlags.cloneID,
4040
}
4141

4242
thingID, err := thing.Create(params)

command/thing/create.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ type CreateParams struct {
1818
// Mandatory - contains the name of the thing
1919
Name string
2020
// Optional - contains the ID of the device to be bound to the thing
21-
Device string
21+
DeviceID string
2222
// Mandatory if device is empty - contains the path of the template file
2323
Template string
2424
// Mandatory if template is empty- name of things to be cloned
25-
Clone string
25+
CloneID string
2626
}
2727

2828
// Create allows to create a new thing
2929
func Create(params *CreateParams) (string, error) {
30-
if params.Template == "" && params.Clone == "" {
30+
if params.Template == "" && params.CloneID == "" {
3131
return "", fmt.Errorf("%s", "provide either a thing(ID) to clone (--clone) or a thing template file (--template)\n")
3232
}
3333

@@ -42,8 +42,8 @@ func Create(params *CreateParams) (string, error) {
4242

4343
var thing *iotclient.Thing
4444

45-
if params.Clone != "" {
46-
thing, err = cloneThing(iotClient, params.Clone)
45+
if params.CloneID != "" {
46+
thing, err = clone(iotClient, params.CloneID)
4747
if err != nil {
4848
return "", err
4949
}
@@ -60,8 +60,8 @@ func Create(params *CreateParams) (string, error) {
6060

6161
thing.Name = params.Name
6262
force := true
63-
if params.Device != "" {
64-
thing.DeviceId = params.Device
63+
if params.DeviceID != "" {
64+
thing.DeviceId = params.DeviceID
6565
}
6666
thingID, err := iotClient.AddThing(thing, force)
6767
if err != nil {
@@ -71,7 +71,7 @@ func Create(params *CreateParams) (string, error) {
7171
return thingID, nil
7272
}
7373

74-
func cloneThing(client iot.Client, thingID string) (*iotclient.Thing, error) {
74+
func clone(client iot.Client, thingID string) (*iotclient.Thing, error) {
7575
clone, err := client.GetThing(thingID)
7676
if err != nil {
7777
return nil, fmt.Errorf("%s: %w", "retrieving the thing to be cloned", err)

0 commit comments

Comments
 (0)