• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
5#
6# HDF is dual licensed: you can use it either under the terms of
7# the GPL, or the BSD license, at your option.
8# See the LICENSE file in the root of this repository for complete details.
9
10
11from hdf_tool_exception import HdfToolException
12from .hdf_add_handler import HdfAddHandler
13from .hdf_delete_handler import HdfDeleteHandler
14from .hdf_get_handler import HdfGetHandler
15from .hdf_set_handler import HdfSetHandler
16from .hdf_ping_handler import HdfPingHandler
17from .hdf_command_error_code import CommandErrorCode
18
19
20class HdfToolCommands(object):
21    def __init__(self):
22        self.commands = {
23            'add': HdfAddHandler,
24            'delete': HdfDeleteHandler,
25            'get': HdfGetHandler,
26            'set': HdfSetHandler,
27            'ping': HdfPingHandler,
28        }
29
30    def run(self, cmd, args):
31        if cmd in self.commands:
32            result = self.commands.get(cmd)(args).run()
33            return result
34        else:
35            raise HdfToolException('unknown cmd: "%s"' % cmd,
36                                   CommandErrorCode.INTERFACE_ERROR)
37
38    def help(self):
39        helps = ['command list:']
40        for cmd in self.commands.keys():
41            helps.append(cmd)
42        return ' '.join(helps)
43