parameters: ()
docstring: Command line main entry
  
      Start lyrebird
  
      * start in default config
      ```
      lyrebird
      ```
      * start with verbose mode
      ```
      lyrebird -v
      ```
      * start without open a web browser
      ```
      lyrebird -b
      ```
      * start with a specified config file
      ```
      lyrebird -c /path/to/your/config/file
      ```
      * start with multipart args
      ```
      lyrebird -v --mock 8080 -c /path/to/your/config/file
      ```
docstring_summary: Command line main entry
docstring_tokens: Command line main entry
function: def main():
      """
      Command line main entry
  
      Start lyrebird
  
      * start in default config
      ```
      lyrebird
      ```
      * start with verbose mode
      ```
      lyrebird -v
      ```
      * start without open a web browser
      ```
      lyrebird -b
      ```
      * start with a specified config file
      ```
      lyrebird -c /path/to/your/config/file
      ```
      * start with multipart args
      ```
      lyrebird -v --mock 8080 -c /path/to/your/config/file
      ```
      """
      parser = argparse.ArgumentParser(prog='lyrebird')
  
      parser.add_argument('-V', '--version', dest='version', action='store_true', help='show lyrebird version')
      parser.add_argument('-v', dest='verbose', action='count', default=0, help='Show verbose log')
      parser.add_argument('--ip', dest='ip', help='Set device ip')
      parser.add_argument('--mock', dest='mock', type=int, help='Set mock server port, default port is 9090')
      parser.add_argument('--extra-mock', dest='extra_mock', type=int, help='Set extra mock server port, default port is 9999')
      parser.add_argument('--proxy', dest='proxy', type=int, help='Set proxy server port, default port is 4272')
      parser.add_argument('--data', dest='data', help='Set data dir, default is "./data/"')
      parser.add_argument('-b', '--no_browser', dest='no_browser',
                          action='store_true', help='Start without open a browser')
      parser.add_argument('-c', '--config', dest='config',
                          help='Start with a config file. Default is "~/.lyrebird/conf.json"')
      parser.add_argument('--log', dest='log', help='Set output log file path')
      parser.add_argument('--script', action='append', help='Set a checker script path')
      parser.add_argument('--plugin', action='append', help='Set a plugin project path')
      parser.add_argument('--database', dest='database', help='Set a database path. Default is "~/.lyrebird/lyrebird.db"')
      parser.add_argument('--es', dest='extra_string', action='append', nargs=2, help='Set a custom config')
  
      subparser = parser.add_subparsers(dest='sub_command')
  
      gen_parser = subparser.add_parser('gen')
      gen_parser.add_argument('path', help='Create plugin project')
  
      args = parser.parse_args()
  
      if args.version:
          print(version.LYREBIRD)
          return
  
      Path('~/.lyrebird').expanduser().mkdir(parents=True, exist_ok=True)
  
      custom_conf = {es[0]:es[1] for es in args.extra_string} if args.extra_string else None
      application._cm = ConfigManager(conf_path=args.config, custom_conf=custom_conf)
  
      # set current ip to config
      if args.ip:
          application._cm.config['ip'] = args.ip
      else:
          try:
              application._cm.config['ip'] = _get_ip()
          except socket.gaierror as e:
              logger.error(f'Failed to get local IP address, error occurs on {e}')
  
      # init file logger after config init
      application._cm.config['verbose'] = args.verbose
      log.init(args.log)
  
      if args.mock:
          application._cm.config['mock.port'] = args.mock
      if args.proxy:
          application._cm.config['proxy.port'] = args.proxy
      if args.data:
          application._cm.config['mock.data'] = str(Path(args.data).expanduser().absolute())
  
      # Set extra mock port
      if args.extra_mock:
          _extra_mock_port = args.extra_mock
      else:
          _extra_mock_port = 9999
      if utils.is_port_in_use(_extra_mock_port):
          _extra_mock_port = utils.find_free_port()
      application._cm.config['extra.mock.port'] = _extra_mock_port
  
      logger.debug(f'Read args: {args}')
  
      if args.sub_command == 'gen':
          logger.debug('EXEC: Plugin project generator')
          gen(args)
      else:
          logger.debug('EXEC: LYREBIRD START')
          run(args)
function_tokens: def main ( ) : parser = argparse . ArgumentParser ( prog = 'lyrebird' ) parser . add_argument ( '-V' , '--version' , dest = 'version' , action = 'store_true' , help = 'show lyrebird version' ) parser . add_argument ( '-v' , dest = 'verbose' , action = 'count' , default = 0 , help = 'Show verbose log' ) parser . add_argument ( '--ip' , dest = 'ip' , help = 'Set device ip' ) parser . add_argument ( '--mock' , dest = 'mock' , type = int , help = 'Set mock server port, default port is 9090' ) parser . add_argument ( '--extra-mock' , dest = 'extra_mock' , type = int , help = 'Set extra mock server port, default port is 9999' ) parser . add_argument ( '--proxy' , dest = 'proxy' , type = int , help = 'Set proxy server port, default port is 4272' ) parser . add_argument ( '--data' , dest = 'data' , help = 'Set data dir, default is "./data/"' ) parser . add_argument ( '-b' , '--no_browser' , dest = 'no_browser' , action = 'store_true' , help = 'Start without open a browser' ) parser . add_argument ( '-c' , '--config' , dest = 'config' , help = 'Start with a config file. Default is "~/.lyrebird/conf.json"' ) parser . add_argument ( '--log' , dest = 'log' , help = 'Set output log file path' ) parser . add_argument ( '--script' , action = 'append' , help = 'Set a checker script path' ) parser . add_argument ( '--plugin' , action = 'append' , help = 'Set a plugin project path' ) parser . add_argument ( '--database' , dest = 'database' , help = 'Set a database path. Default is "~/.lyrebird/lyrebird.db"' ) parser . add_argument ( '--es' , dest = 'extra_string' , action = 'append' , nargs = 2 , help = 'Set a custom config' ) subparser = parser . add_subparsers ( dest = 'sub_command' ) gen_parser = subparser . add_parser ( 'gen' ) gen_parser . add_argument ( 'path' , help = 'Create plugin project' ) args = parser . parse_args ( ) if args . version : print ( version . LYREBIRD ) return Path ( '~/.lyrebird' ) . expanduser ( ) . mkdir ( parents = True , exist_ok = True ) custom_conf = { es [ 0 ] : es [ 1 ] for es in args . extra_string } if args . extra_string else None application . _cm = ConfigManager ( conf_path = args . config , custom_conf = custom_conf ) # set current ip to config if args . ip : application . _cm . config [ 'ip' ] = args . ip else : try : application . _cm . config [ 'ip' ] = _get_ip ( ) except socket . gaierror as e : logger . error ( f'Failed to get local IP address, error occurs on {e}' ) # init file logger after config init application . _cm . config [ 'verbose' ] = args . verbose log . init ( args . log ) if args . mock : application . _cm . config [ 'mock.port' ] = args . mock if args . proxy : application . _cm . config [ 'proxy.port' ] = args . proxy if args . data : application . _cm . config [ 'mock.data' ] = str ( Path ( args . data ) . expanduser ( ) . absolute ( ) ) # Set extra mock port if args . extra_mock : _extra_mock_port = args . extra_mock else : _extra_mock_port = 9999 if utils . is_port_in_use ( _extra_mock_port ) : _extra_mock_port = utils . find_free_port ( ) application . _cm . config [ 'extra.mock.port' ] = _extra_mock_port logger . debug ( f'Read args: {args}' ) if args . sub_command == 'gen' : logger . debug ( 'EXEC: Plugin project generator' ) gen ( args ) else : logger . debug ( 'EXEC: LYREBIRD START' ) run ( args )