Command-line programs · 12 / 15 Exercise Hard

Text tool with subcommands

Objective

Create a command-line tool with subcommands, like git does. Each subcommand is a different action with its own arguments. The arguments of each test are passed to the program as if you typed them in the terminal (they appear in the test cases).

Instructions

  • Use parser.add_subparsers with dest="command" (required) and define the subcommands upper, reverse, stats and repeat (the latter with an integer argument times).
  • Read the text from standard input, line by line.
  • upper shows each line in uppercase; reverse, each line reversed; repeat times, each line repeated times times separated by spaces.
  • stats shows Lines: k and Words: k (the total number of words in all the lines).
Input
ab cd
ef
Output
ab cd ab cd
ef ef

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise