Skip to content

Commit 965c646

Browse files
Добавление примеров использования и описания в argparse
1 parent 8ac1e98 commit 965c646

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.2.0
3+
rev: v4.3.0
44
hooks:
55
- id: check-builtin-literals
66
- id: check-docstring-first
@@ -17,7 +17,7 @@ repos:
1717
- id: isort
1818

1919
- repo: https://github.com/PyCQA/flake8
20-
rev: 4.0.1
20+
rev: 5.0.4
2121
hooks:
2222
- id: flake8
2323
additional_dependencies:

vkms/argparser.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,26 @@ def _format_action_invocation(self, action):
1313
return '/'.join(action.option_strings) + ' ' + args_string
1414

1515

16+
description = 'Utility for saving VKontakte conversations'
17+
epilog = '''examples:
18+
%(prog)s -vv -i c45,558891166 dump --export-json
19+
%(prog)s -e 100,-22822305 parse -f html
20+
%(prog)s atch --ts photos,audios
21+
'''
22+
23+
1624
def parse_args():
1725
"""
1826
Создает объект парсера и парсит аргументы
1927
2028
Returns:
2129
argparse.Namespace: Набор аргументов парсера
2230
"""
23-
parser = ArgumentParser(formatter_class=CustomHelpFormatter)
31+
parser = ArgumentParser(
32+
formatter_class=CustomHelpFormatter,
33+
description=description,
34+
epilog=epilog
35+
)
2436

2537
parser.add_argument(
2638
'-o',
@@ -66,7 +78,9 @@ def parse_args():
6678
'dump',
6779
help='Save only the necessary information (VK API method outputs) '
6880
'in a machine-friendly format (SQLite + JSON) for further processing',
69-
formatter_class=CustomHelpFormatter
81+
formatter_class=CustomHelpFormatter,
82+
description=description,
83+
epilog=epilog
7084
)
7185

7286
parser_dump.add_argument(
@@ -105,7 +119,9 @@ def parse_args():
105119
parser_parse = subparsers.add_parser(
106120
'parse',
107121
help='Convert machine-friendly JSON format to human-readable',
108-
formatter_class=CustomHelpFormatter
122+
formatter_class=CustomHelpFormatter,
123+
description=description,
124+
epilog=epilog
109125
)
110126

111127
parser_parse.add_argument(
@@ -121,7 +137,9 @@ def parse_args():
121137
parser_atch = subparsers.add_parser(
122138
'atch',
123139
help='Download messages attachments (photos, audio, etc.)',
124-
formatter_class=CustomHelpFormatter
140+
formatter_class=CustomHelpFormatter,
141+
description=description,
142+
epilog=epilog
125143
)
126144

127145
parser_atch.add_argument(

0 commit comments

Comments
 (0)