1+ """Module containing functions that provide functionality related to commandline arguments parsing"""
2+
13from argparse import ArgumentParser , Namespace
24from typing import Callable
35
46from app .command .io import map_input , map_output
57from app .io .format_factory import get_reader_from_format , KnownFormat , get_writer_from_format
6- from app .operation .bgr2rgb import BGR2RGBOperation
7- from app .operation .flip import FlipOperation
8- from app .operation .grayscale import GrayscaleOperation
9- from app .operation .histogram_equalization import HistogramEqualizationOperation
10- from app .operation .identity import IdentityOperation
11- from app .operation .operation import Operation
12- from app .operation .roll import RollOperation
13-
14- from app .operation .rotate90 import Rotate90Operation
8+ from app .operation import Rotate90 , Identity , Flip , BGR2RGB , Roll , Grayscale , HistogramEqualization , IOperation
159
1610
1711def get_parser () -> ArgumentParser :
12+ """Functions that initialises the Argument Parser"""
13+
1814 parser = ArgumentParser (prog = 'PROG' ,
1915 description = 'Image CLI that performs different image operations like scaling, rotating etc' )
20- parser .add_argument ('input' ,
16+ parser .add_argument ('-- input' ,
2117 nargs = '?' ,
2218 default = None ,
2319 help = 'program input' )
24- parser .add_argument ('output' ,
20+ parser .add_argument ('-- output' ,
2521 nargs = '?' ,
2622 default = None ,
2723 help = 'program output' )
@@ -32,7 +28,7 @@ def get_parser() -> ArgumentParser:
3228 help = 'program output' )
3329
3430 subparser = parser .add_subparsers (required = True ,
35- help = 'Command to be performed on an image' )
31+ help = 'Command or operation to be performed on an image' )
3632
3733 for operation_class in available_commands ():
3834 operation = operation_class ()
@@ -46,7 +42,8 @@ def get_parser() -> ArgumentParser:
4642 return parser
4743
4844
49- def prepare_command (command : Operation ) -> Callable [[Namespace ], int ]:
45+ def prepare_command (command : IOperation ) -> Callable [[Namespace ], int ]:
46+ """Function that decorates the operation in order to provide input and output to it"""
5047
5148 def wrapper (args : Namespace ) -> int :
5249 data_format = KnownFormat .from_string (args .format )
@@ -64,12 +61,14 @@ def wrapper(args: Namespace) -> int:
6461
6562
6663def available_commands ():
64+ """Function that returns all the supported commandline operations by the program"""
65+
6766 return [
68- Rotate90Operation ,
69- IdentityOperation ,
70- FlipOperation ,
71- BGR2RGBOperation ,
72- RollOperation ,
73- GrayscaleOperation ,
74- HistogramEqualizationOperation ,
67+ Rotate90 ,
68+ Identity ,
69+ Flip ,
70+ BGR2RGB ,
71+ Roll ,
72+ Grayscale ,
73+ HistogramEqualization ,
7574 ]
0 commit comments