options.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/06/22
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : command line params or config from file
  8. """
  9. import sys,os,re
  10. import argparse
  11. from collections import OrderedDict
  12. from .utils.frozen_dir import get_app_path
  13. def parse_args():
  14. """
  15. parse command line params
  16. """
  17. parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description='''
  18. crawl_sse
  19. command line params:
  20. python main.py --path F:\workspace\Folder\git_commit.py
  21. ''', epilog="Believe that with the above description, " +
  22. "you can start working right away. Wish you success")
  23. # group = parser.add_mutually_exclusive_group()
  24. parser.add_argument('cmd', help='cmd: commit, sync, check', choices=['commit','sync', 'check', 'help','version'] , default='help')
  25. parser.add_argument('--path', help='set a path')
  26. args = parser.parse_args()
  27. if args is None:
  28. parser.print_help()
  29. sys.exit(1)
  30. # remove None
  31. command_line_conf = OrderedDict(
  32. {k: v for k, v in args.__dict__.items() if v is not None}
  33. )
  34. system_conf = user_conf = custom_conf = OrderedDict()
  35. system_conf.update(command_line_conf)
  36. app_path = get_app_path()
  37. system_conf["app_path"] = app_path
  38. return system_conf
  39. def _read_custom_conf(config_path: str) -> OrderedDict:
  40. """read custom config file"""
  41. pass
  42. def _read_user_conf() -> OrderedDict:
  43. """read user config file"""
  44. pass