shortargs.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # The contents of this file are subject to the BitTorrent Open Source License
  2. # Version 1.1 (the License). You may not copy or use this file, in either
  3. # source code or executable form, except in compliance with the License. You
  4. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10. # Written by David Harrison
  11. shortforms = { "-p" : "--port",
  12. "-u" : "--use_factory_defaults",
  13. "-h" : "--help",
  14. "-?" : "--help",
  15. "--usage" : "--help"
  16. }
  17. def convert_from_shortforms(argv):
  18. """
  19. Converts short-form arguments onto the corresponding long-form, e.g.,
  20. -p becomes --port.
  21. """
  22. assert type(argv)==list
  23. newargv = []
  24. for arg in argv:
  25. if arg in shortforms:
  26. newargv.append(shortforms[arg])
  27. else:
  28. newargv.append(arg)
  29. return newargv