Skip to content

Commit a5759ad

Browse files
committed
feat: added parser
1 parent fd8306d commit a5759ad

11 files changed

Lines changed: 83 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools", "numpy==2.3.5"]
2+
requires = ["setuptools", "numpy==2.3.5", "cython"]
33
build-backend = "setuptools.build_meta"

src/app/cmd/__init__.py

Whitespace-only changes.

src/app/cmd/command.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from abc import ABC, abstractmethod
2+
from argparse import Namespace, ArgumentParser
3+
4+
5+
class CmdCommand(ABC):
6+
7+
@classmethod
8+
@abstractmethod
9+
def name(cls) -> str:
10+
pass
11+
12+
@classmethod
13+
@abstractmethod
14+
def help(cls) -> str:
15+
pass
16+
17+
@classmethod
18+
@abstractmethod
19+
def parser(cls, parser: ArgumentParser) -> str:
20+
pass
21+
22+
@abstractmethod
23+
def __call__(self, args: Namespace) -> None:
24+
pass
25+

src/app/cmd/parser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from argparse import ArgumentParser
2+
3+
from app.cmd.command import CmdCommand
4+
from app.cmd.rotate import RotateCommand
5+
6+
7+
def get_parser() -> ArgumentParser:
8+
parser = ArgumentParser(prog='PROG',
9+
description='Image CLI that performs different image operations like scaling, rotating etc')
10+
11+
subparser = parser.add_subparsers(title='command',
12+
required=True,
13+
help='Command to be performed on an image')
14+
15+
command_class: type[CmdCommand]
16+
for command_class in [RotateCommand]:
17+
command = command_class()
18+
parser = subparser.add_parser(name=command_class.name(),
19+
help=command_class.help())
20+
parser.set_defaults(func=command.__call__)
21+
22+
return parser

src/app/cmd/rotate.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from abc import abstractmethod, ABC
2+
from argparse import Namespace
3+
4+
5+
class RotateCommand(ABC):
6+
7+
@classmethod
8+
@abstractmethod
9+
def name(cls) -> str:
10+
return 'rotate'
11+
12+
@classmethod
13+
@abstractmethod
14+
def help(cls) -> str:
15+
return 'Rotate the image '
16+
17+
@abstractmethod
18+
def __call__(self, args: Namespace) -> None:
19+
pass

src/app/cmd/scale.py

Whitespace-only changes.

src/app/hello.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/app/imcli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from app.cmd.parser import get_parser
2+
3+
4+
def main() -> None:
5+
args = get_parser().parse_args()
6+
args.func(args)
7+
8+
if __name__ == '__main__':
9+
main()

src/app/img/__init__.py

Whitespace-only changes.

src/app/img/read.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
import numpy as np
4+
5+
def read_bitmap_image(path: Path) -> np.ndarray:
6+
image_bytes = path.read_bytes()
7+
breakpoint()

0 commit comments

Comments
 (0)