Skip to content

Commit

Permalink
[cli-tool]: add subcommands add, remove, status, result
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotics010 committed Sep 22, 2023
1 parent 86391c3 commit 2fc239e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Current project is under active development and is not ready yet to be in use.
~/cycle_on/service$ cmake --build build
~/cycle_on/service$ (cd build && ctest)
~/cycle_on/service$ ./build/src/hello_world
~/cycle_on/service$ ./build/src/service
```

### cli-tool notes
Expand All @@ -26,7 +26,11 @@ $ python3 -m pip install build
$ python3 -m pip install setuptools
$ python3 -m pip install --user virtualenv --force-reinstall
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py data/config.json
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py add --reuse_global_config
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py remove id
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py status id
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py result id
~/cycle_on/cli_tool$ python3 -m pytest test/
~/cycle_on/cli_tool$ python3 -m build
~/cycle_on/cli_tool$ python3 -m pip install dist/cycleon-0.0.1-py3-none-any.whl --force-reinstall
Expand Down
File renamed without changes.
44 changes: 36 additions & 8 deletions cli_tool/src/cycleon/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,57 @@


def process(args):
GLOBAL_CONFIG_PATH = 'data/global_config.json'
config_reader = ConfigReader()
config_reader.implementation = JsonConfig()
config = config_reader.Open(args.config)
config = config_reader.Open(GLOBAL_CONFIG_PATH)

client = Client()
client.interface = TcpClient(
address=config.network.address,
port=config.network.port)
client.adapter = JsonTcpAdapter()

# ToDo: add low-level client cmd execute
action_id = client.Add(config.action)
print(f'action_id: {action_id}')
# client.Remove(action_id)
# status = client.GetStatus(action_id)
# result = client.GetResult(action_id)
if args.command == 'add':
action_id = client.Add(config.action)
print(f'added with action_id: {action_id}')
elif args.command == 'remove':
client.Remove(int(args.id))
print(f'removed action_id: {args.id}')
elif args.command == 'status':
status = client.GetStatus(int(args.id))
print(f'status of action_id {args.id}: {status}')
elif args.command == 'result':
result = client.GetResult(int(args.id))
print(f'result of action_id {args.id}: {result}')
else:
raise RuntimeError(f'unsupported command "{args.command}"')

# ToDo: add high-level scenario group execution


def main():
parser = argparse.ArgumentParser()
parser.add_argument('config', help='path to config file')
# parser.add_argument('--config', help='path to global config file', required=True)

subparsers = parser.add_subparsers(help='sub-command', required=True, dest='command')

add_cmd_subparser = subparsers.add_parser('add', help='request new action to perform')
add_config_group = add_cmd_subparser.add_mutually_exclusive_group(required=True)
add_config_group.add_argument('--reuse_global_config', action='store_true',
help='get action from global config')
add_config_group.add_argument('--config', type=str,
help='path to config file with action to perform')

remove_cmd_subparser = subparsers.add_parser('remove', help='cancel selected action')
remove_cmd_subparser.add_argument('id', help='unique index of the action')

status_cmd_subparser = subparsers.add_parser('status', help='get status of selected action')
status_cmd_subparser.add_argument('id', help='unique index of the action')

result_cmd_subparser = subparsers.add_parser('result', help='get result of selected action')
result_cmd_subparser.add_argument('id', help='unique index of the action')

args = parser.parse_args()

process(args)
Expand Down
5 changes: 4 additions & 1 deletion cli_tool/src/cycleon/network/message/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Type(Enum):
INVALID = 0
ADD_ACTION = 1
# REMOVE_ACTION = 2
REMOVE_ACTION = 2
GET_ACTION_STATUS = 3
GET_ACTION_RESULT = 4

Expand All @@ -28,6 +28,9 @@ class Result:
def __init__(self) -> None:
self._type = ResultType.INVALID
self._message = ''

def __str__(self) -> str:
return f'({self._type},{self._message})'

@property
def type(self) -> ResultType:
Expand Down

0 comments on commit 2fc239e

Please sign in to comment.