Skip to content

Commit

Permalink
More consistent twin-id argument (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
montgomp authored Jun 10, 2020
1 parent 4657fdc commit f3fa545
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions azext_iot/digitaltwins/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ def load_digitaltwins_help():
- name: Create a relationship between two digital twins.
text: >
az dt twin relationship create -n {instance_name} --relationship-id {relationship_id} --relationship contains
--source {source_twin_id} --target {target_twin_id}
--twin-id {source_twin_id} --target {target_twin_id}
- name: Create a relationship with initialized properties between two digital twins.
text: >
az dt twin relationship create -n {instance_name} --relationship-id {relationship_id} --relationship contains
--source {source_twin_id} --target {target_twin_id}
--twin-id {source_twin_id} --target {target_twin_id}
--properties '{"ownershipUser": "me", "ownershipDepartment": "Computer Science"}'
"""

Expand Down
4 changes: 2 additions & 2 deletions azext_iot/digitaltwins/commands_twins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def delete_twin(cmd, name, twin_id, resource_group_name=None):
def create_relationship(
cmd,
name,
source_twin_id,
twin_id,
target_twin_id,
relationship_id,
relationship,
Expand All @@ -51,7 +51,7 @@ def create_relationship(
):
twin_provider = TwinProvider(cmd=cmd, name=name, rg=resource_group_name)
return twin_provider.add_relationship(
source_twin_id=source_twin_id,
twin_id=twin_id,
target_twin_id=target_twin_id,
relationship_id=relationship_id,
relationship=relationship,
Expand Down
22 changes: 12 additions & 10 deletions azext_iot/digitaltwins/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ def load_digitaltwins_arguments(self, _):
options_list=["--relationship-id", "-r"],
help="Relationship Id.",
)
context.argument(
"source_twin_id",
options_list=["--source-twin-id", "--source", "-s"],
help="The source twin Id for a relationship.",
)
context.argument(
"target_twin_id",
options_list=["--target-twin-id", "--target", "-t"],
help="The target twin Id for a relationship.",
)
context.argument(
"relationship",
options_list=["--relationship", "--kind"],
Expand Down Expand Up @@ -237,6 +227,18 @@ def load_digitaltwins_arguments(self, _):
help="The path to the DTDL component. If set, telemetry will be emitted on behalf of the component.",
)

with self.argument_context("dt twin relationship") as context:
context.argument(
"twin_id",
options_list=["--twin-id", "-t"],
help="The source twin Id for a relationship.",
)
context.argument(
"target_twin_id",
options_list=["--target-twin-id", "--target"],
help="The target twin Id for a relationship.",
)

with self.argument_context("dt twin relationship create") as context:
context.argument(
"properties",
Expand Down
4 changes: 2 additions & 2 deletions azext_iot/digitaltwins/providers/twin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def delete(self, twin_id):

def add_relationship(
self,
source_twin_id,
twin_id,
target_twin_id,
relationship_id,
relationship,
Expand All @@ -117,7 +117,7 @@ def add_relationship(

logger.info("Relationship payload %s", json.dumps(relationship_request))
return self.twins_sdk.add_relationship(
id=source_twin_id,
id=twin_id,
relationship_id=relationship_id,
relationship=relationship_request,
if_none_match="*",
Expand Down
2 changes: 1 addition & 1 deletion azext_iot/tests/digitaltwins/test_dt_twin_lifecycle_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_dt_twin(self):
)

twin_relationship_create_result = self.cmd(
"dt twin relationship create -n {} -g {} --relationship-id {} --relationship {} --source-twin-id {} "
"dt twin relationship create -n {} -g {} --relationship-id {} --relationship {} --twin-id {} "
"--target-twin-id {} --properties '{}'".format(
self.instance_name,
self.group_names[0],
Expand Down

0 comments on commit f3fa545

Please sign in to comment.