__init__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. # Copyright 2021 The HuggingFace Team. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import argparse
  16. from .config import config_command_parser
  17. from .config_args import default_config_file, load_config_from_file # noqa: F401
  18. from .default import default_command_parser
  19. from .update import update_command_parser
  20. def get_config_parser(subparsers=None):
  21. parent_parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
  22. # The main config parser
  23. config_parser = config_command_parser(subparsers)
  24. # The subparser to add commands to
  25. subcommands = config_parser.add_subparsers(title="subcommands", dest="subcommand")
  26. # Then add other parsers with the parent parser
  27. default_command_parser(subcommands, parents=[parent_parser])
  28. update_command_parser(subcommands, parents=[parent_parser])
  29. return config_parser
  30. def main():
  31. config_parser = get_config_parser()
  32. args = config_parser.parse_args()
  33. if not hasattr(args, "func"):
  34. config_parser.print_help()
  35. exit(1)
  36. # Run
  37. args.func(args)
  38. if __name__ == "__main__":
  39. main()