ebook_homebrew.cli.execute_auto()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2 1
import argparse
3
4 1
from ebook_homebrew.helper import auto
5 1
from ebook_homebrew.helper import show_version
6 1
from ebook_homebrew.helper import rest_api
7
8
9 1
def execute_auto(args_auto):
10 1
    auto(args_auto)
11
12
13 1
def execute_api(args_api):
14 1
    rest_api(args_api)
15
16
17 1
def main():
18 1
    parser = argparse.ArgumentParser(
19
        prog="ebook_homebrew",
20
        usage="ebookhomebrew",
21
        description="You can make e-books for some image files",
22
        epilog="More information? Access here: https://github.com/tubone24/ebook_homebrew",
23
        add_help=True,
24
    )
25 1
    parser.add_argument("-v", "--version", action="store_true", help="Show version")
26
27 1
    subparsers = parser.add_subparsers(
28
        description='Choose subcommands. Usually choose "auto"'
29
    )
30
31 1
    parser_auto = subparsers.add_parser(
32
        "auto",
33
        description="Make only digit file name, " "convert e-book file such as PDF",
34
        help="Make only digit file name, " "convert e-book file such as PDF",
35
    )
36
37 1
    parser_api = subparsers.add_parser(
38
        "api", description="Run Rest API server.", help="Provides Rest API interfaces."
39
    )
40
41 1
    parser_api.add_argument(
42
        "-p",
43
        "--port",
44
        action="store",
45
        nargs=1,
46
        const=None,
47
        default=None,
48
        required=True,
49
        type=int,
50
        help="API Server Port",
51
        metavar="PORT",
52
    )
53
54 1
    parser_auto.set_defaults(handler=execute_auto)
55 1
    parser_api.set_defaults(handler=execute_api)
56
57 1
    parser_auto.add_argument(
58
        "-s",
59
        "--src_dir",
60
        action="store",
61
        nargs=1,
62
        const=None,
63
        default=None,
64
        required=True,
65
        type=str,
66
        help="Source directory which put original image files.",
67
        metavar="SRC_DIR",
68
    )
69
70 1
    parser_auto.add_argument(
71
        "--dst_dir",
72
        action="store",
73
        nargs=1,
74
        const=None,
75
        default=None,
76
        type=str,
77
        help="Destination directory which put e-book file.",
78
        metavar="DST_DIR",
79
    )
80
81 1
    parser_auto.add_argument(
82
        "-d",
83
        "--digit",
84
        action="store",
85
        nargs=1,
86
        const=None,
87
        default=None,
88
        required=True,
89
        type=str,
90
        help="Serial number digits you remain file name",
91
        metavar="N,N",
92
    )
93
94 1
    parser_auto.add_argument(
95
        "-e",
96
        "--extension",
97
        action="store",
98
        nargs=1,
99
        const=None,
100
        default=None,
101
        required=True,
102
        type=str,
103
        help="Destination directory which put e-book file.",
104
        metavar="EXT",
105
    )
106
107 1
    parser_auto.add_argument(
108
        "-f",
109
        "--filename",
110
        action="store",
111
        nargs=1,
112
        const=None,
113
        default=None,
114
        required=True,
115
        type=str,
116
        help="Destination directory which put e-book file.",
117
        metavar="FILENAME",
118
    )
119
120 1
    parser_auto.add_argument(
121
        "-m",
122
        "--manual",
123
        action="store_true",
124
        help="Duplicate file name, solving manually.",
125
    )
126
127 1
    parser_auto.add_argument(
128
        "-r", "--remove", action="store_true", help="Remove original image file."
129
    )
130
131 1
    parser_auto.add_argument(
132
        "-y", "--assume_yes", action="store_true", help="no verify users."
133
    )
134
135 1
    parser_make_zip = subparsers.add_parser(
136
        "makezip",
137
        description="Make zip file for files " "which you choose extension.",
138
        help="Make zip file for adding specify extension files.",
139
    )
140
141 1
    parser_make_zip.add_argument(
142
        "-s",
143
        "--src_dir",
144
        action="store",
145
        nargs=1,
146
        const=None,
147
        default=None,
148
        required=True,
149
        type=str,
150
        help="Source directory which put original image files.",
151
        metavar="SRC_DIR",
152
    )
153
154 1
    parser_make_zip.add_argument(
155
        "--dst_dir",
156
        action="store",
157
        nargs=1,
158
        const=None,
159
        default=None,
160
        type=str,
161
        help="Destination directory which put e-book file.",
162
        metavar="DST_DIR",
163
    )
164
165 1
    parser_make_zip.add_argument(
166
        "-e",
167
        "--extension",
168
        action="store",
169
        nargs=1,
170
        const=None,
171
        default=None,
172
        required=True,
173
        type=str,
174
        help="Destination directory which put e-book file.",
175
        metavar="EXT",
176
    )
177
178 1
    parser_make_zip.add_argument(
179
        "-f",
180
        "--filename",
181
        action="store",
182
        nargs=1,
183
        const=None,
184
        default=None,
185
        required=True,
186
        type=str,
187
        help="Destination directory which put e-book file.",
188
        metavar="FILENAME",
189
    )
190
191 1
    parser_make_zip.add_argument(
192
        "-r", "--remove", action="store_true", help="Remove original image file."
193
    )
194
195 1
    parser_make_zip.add_argument(
196
        "-y", "--assume_yes", action="store_true", help="no verify users."
197
    )
198
199 1
    args = parser.parse_args()
200
201 1
    if hasattr(args, "handler"):
202 1
        args.handler(args)
203
    elif args.version:
204
        show_version()
205
    else:
206
        parser.print_help()
207
208
209 1
if __name__ == "__main__":
210
    main()
211