-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.py
More file actions
executable file
·60 lines (53 loc) · 1.81 KB
/
decode.py
File metadata and controls
executable file
·60 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""decode.py is the entry script for CLI decoding"""
import sys
import click
from rpgmaker_mv_decoder.callbacks import show_version
from rpgmaker_mv_decoder.cli_help import DecodeHelp
from rpgmaker_mv_decoder.constants import (
CLI_OVERWRITE_HELP,
CLI_VERSION_HELP,
CLICK_DST_PATH,
CLICK_SRC_PATH,
CMD_HELP_DECODE,
TYPE_HELP,
)
from rpgmaker_mv_decoder.projectdecoder import ProjectDecoder
from rpgmaker_mv_decoder.projectkeyfinder import ProjectKeyFinder
@click.command(cls=DecodeHelp, help=CMD_HELP_DECODE)
@click.argument("source", required=True, metavar="<Source>", type=CLICK_SRC_PATH)
@click.argument("destination", required=True, metavar="<Destination>", type=CLICK_DST_PATH)
@click.argument("key", type=str, required=False, metavar="[<Key>]")
@click.option("--detect_type", is_flag=True, help=TYPE_HELP)
@click.option(
"--version",
is_flag=True,
callback=show_version,
expose_value=False,
is_eager=True,
help=CLI_VERSION_HELP,
)
@click.option("--overwrite", is_flag=True, help=CLI_OVERWRITE_HELP)
def decode(
source: click.Path = None,
destination: click.Path = None,
key: str = None,
detect_type: bool = False,
overwrite: bool = False,
) -> None:
"""`decode` The main function
Args:
- `source` (`click.Path`): Source directory
- `destination` (`click.Path`): Destination directory
- `key` (`str`, optional): Hex key to use. Defaults to None
- `detect_type` (`bool`): If file should have extensions based on file contents
"""
if key is None:
key = ProjectKeyFinder(source).find_key()
decoder = ProjectDecoder(source, destination, key)
if overwrite:
decoder.overwrite = True
decoder.decode(detect_type)
return 0
if __name__ == "__main__":
sys.exit(decode()) # pragma: no cover