Skip to content

Commit 5944771

Browse files
committed
refactor: move cli setup into __main__.py
1 parent 535dfcb commit 5944771

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_requires =
3737

3838
[options.entry_points]
3939
console_scripts =
40-
makeclean = makeclean:main
40+
makeclean = makeclean.__main__:cli
4141

4242
[flake8]
4343
max-complexity = 12

src/makeclean/__init__.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,13 @@
22
from os.path import exists, isdir
33
from shutil import rmtree
44

5-
import click
5+
from click import echo, style
66

77

88
__version__ = "0.0.1-dev0"
99

1010

11-
@click.command()
12-
@click.help_option("--help", "-h")
13-
@click.option("--verbose", "-v", is_flag=True, default=False)
14-
@click.option("--version", "-V", is_flag=True, default=False)
15-
@click.argument("PATH", nargs=-1, type=click.Path())
16-
def main(path, verbose, version):
17-
"""This utility is meant for use in makefiles as the clean target or similar usecases.
18-
It takes an arbitray number of PATH objects and removes them if they exists.
19-
Folders will be remove recursivly."""
20-
if version:
21-
print(f"makeclean.py v{__version__}")
22-
return
23-
clean(path, verbose)
24-
25-
26-
def clean(path: list[str|PathLike], verbose=False):
11+
def clean(path: list[str | PathLike], verbose=False):
2712
"""Removes all given Path-Objects, meaning files are deleted and
2813
directorys are removed recurlivly.
2914
@@ -34,15 +19,15 @@ def clean(path: list[str|PathLike], verbose=False):
3419
for p in path:
3520
if not exists(p):
3621
if verbose:
37-
click.echo(f'{click.style("skip", fg="yellow")}: {p}')
22+
echo(f'{style("skip", fg="yellow")}: {p}')
3823
continue
3924
if isdir(p):
4025
if not p.endswith("/"):
4126
p += "/"
4227
if verbose:
43-
click.echo(f'{click.style("dir", fg="bright_cyan")}: {p}')
28+
echo(f'{style("dir", fg="bright_cyan")}: {p}')
4429
rmtree(p)
4530
else:
4631
if verbose:
47-
click.echo(f'{click.style("file", fg="blue")}: {p}')
32+
echo(f'{style("file", fg="blue")}: {p}')
4833
remove(p)

src/makeclean/__main__.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
from . import main
1+
import click
2+
3+
from . import __version__, clean
4+
5+
6+
@click.command()
7+
@click.help_option("--help", "-h")
8+
@click.option("--verbose", "-v", is_flag=True, default=False)
9+
@click.option("--version", "-V", is_flag=True, default=False)
10+
@click.argument("PATH", nargs=-1, type=click.Path())
11+
def cli(path, verbose, version):
12+
"""This utility is meant for use in makefiles as the clean target or similar
13+
usecases. It takes an arbitray number of PATH objects and removes them if they
14+
exists. Folders will be remove recursivly."""
15+
if version:
16+
print(f"makeclean.py v{__version__}")
17+
return
18+
clean(path, verbose)
219

320

421
if __name__ == "__main__":
5-
main()
22+
cli()

0 commit comments

Comments
 (0)