string_cli.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import sys
  2. def print_help():
  3. help_text = """
  4. Usage: python string_cli.py <command> <string>
  5. Commands:
  6. reverse - Reverses the input string.
  7. uppercase - Converts the input string to uppercase.
  8. lowercase - Converts the input string to lowercase.
  9. spongebob - Converts the input string to spongebob case.
  10. length - Returns the length of the input string.
  11. scramble - Randomly scrambles the characters in the input string.
  12. """
  13. print(help_text)
  14. if __name__ == '__main__':
  15. if len(sys.argv) == 2 and sys.argv[1] == '--help':
  16. print_help()
  17. sys.exit(0)
  18. elif len(sys.argv) < 3:
  19. print('Usage: python string_cli.py <command> <string>')
  20. sys.exit(1)
  21. command = sys.argv[1]
  22. input_string = sys.argv[2]
  23. if command == 'reverse':
  24. from commands.reverse import reverse_string
  25. print(reverse_string(input_string))
  26. elif command == 'uppercase':
  27. from commands.uppercase import to_uppercase
  28. print(to_uppercase(input_string))
  29. elif command == 'lowercase':
  30. from commands.lowercase import to_lowercase
  31. print(to_lowercase(input_string))
  32. elif command == 'spongebob':
  33. from commands.spongebob import spongebob_case
  34. print(spongebob_case(input_string))
  35. elif command == 'length':
  36. from commands.length import string_length
  37. print(string_length(input_string))
  38. elif command == 'scramble':
  39. from commands.scramble import scramble_string
  40. print(scramble_string(input_string))
  41. else:
  42. print('Invalid command!')