Skip to content

Commit 0f9506c

Browse files
authored
Merge pull request #32 from intezer/feature/command-aliases
feat: add command aliases with dashes and bump version to 1.12.0
2 parents a4d3f19 + 4090d02 commit 0f9506c

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ on:
1111
jobs:
1212
build:
1313

14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-24.04
1515
strategy:
1616
matrix:
1717
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1818

1919
steps:
2020
- uses: actions/checkout@v3
2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v3
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- name: Install dependencies

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.12.0
2+
-----
3+
- Add command aliases with dashes (e.g., analyze-by-list) while maintaining backward compatibility with underscore versions
4+
15
1.11.2
26
-----
37
- Upgrade intezer-SDK to 1.21.4

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ For complete documentation please run `intezer-analyze analyze --help`
4949
Send a text file with list of hashes
5050

5151
### Usage
52-
`intezer-analyze analyze_by_list PATH`
52+
`intezer-analyze analyze-by-list PATH`
5353

5454
### Parameters
5555
PATH: Path to txt file.
5656

5757
### Example
5858
Send txt file with hashes for analysis:
5959

60-
$ intezer-analyze analyze_by_list ~/files/hashes.txt
60+
$ intezer-analyze analyze-by-list ~/files/hashes.txt
6161

62-
For complete documentation please run `intezer-analyze analyze_by_list --help`
62+
For complete documentation please run `intezer-analyze analyze-by-list --help`
6363

6464
## Index
6565
Send a file or a directory for indexing
@@ -89,7 +89,7 @@ For complete documentation please run `intezer-analyze index --help`
8989
Send a text file with list of hashes to index
9090

9191
### Usage
92-
`intezer-analyze index_by_list PATH --index-as=INDEX [FAMILY_NAME]`
92+
`intezer-analyze index-by-list PATH --index-as=INDEX [FAMILY_NAME]`
9393

9494
### Parameters
9595
PATH: Path to txt file
@@ -101,50 +101,50 @@ FAMILY_NAME: The family name (optional)
101101
### Example
102102
Send a file with hashes and verdict for indexing:
103103

104-
$ intezer-analyze index_by_list ~/files/hashes.txt --index-as=malicious family_name
104+
$ intezer-analyze index-by-list ~/files/hashes.txt --index-as=malicious family_name
105105

106-
For complete documentation please run `intezer-analyze index --help`
106+
For complete documentation please run `intezer-analyze index-by-list --help`
107107

108108
## Upload offline endpoint scan
109109
Upload an offline scan created by running the Intezer Endpoint Scanner with '-o' flag
110110

111111
### Usage
112-
`intezer-analyze upload_endpoint_scan OFFLINE_SCAN_DIRECTORY`
112+
`intezer-analyze upload-endpoint-scan OFFLINE_SCAN_DIRECTORY`
113113

114114
### Parameters
115115
OFFLINE_SCAN_DIRECTORY: Path to directory with offline endpoint scan results
116116

117117
### Examples:
118118
Upload a directory with offline endpoint scan results:
119119

120-
$ intezer-analyze upload_endpoint_scan /home/user/offline_scans/scan_MYPC_2019-01-01_00-00-00
120+
$ intezer-analyze upload-endpoint-scan /home/user/offline_scans/scan_MYPC_2019-01-01_00-00-00
121121

122-
For complete documentation plrase run `intezer-analyze upload_endpoint_scan --help`
122+
For complete documentation please run `intezer-analyze upload-endpoint-scan --help`
123123

124124
## Upload multiple offline endpoint scans
125125
Upload multiple offline scans created by running the Intezer Endpoint Scanner with '-o' flag
126126

127127
### Usage
128-
`intezer-analyze upload_endpoint_scans_in_directory OFFLINE_SCANS_ROOT_DIRECTORY`
128+
`intezer-analyze upload-endpoint-scans-in-directory OFFLINE_SCANS_ROOT_DIRECTORY`
129129

130130
### Parameters
131131
OFFLINE_SCANS_ROOT_DIRECTORY: Path to root directory containing offline endpoint scan results
132132

133133
### Examples:
134134
Upload a directory with offline endpoint scan results:
135135

136-
$ intezer-analyze upload_endpoint_scans /home/user/offline_scans
136+
$ intezer-analyze upload-endpoint-scans-in-directory /home/user/offline_scans
137137

138-
For complete documentation please run `intezer-analyze upload_endpoint_scans_in_directory --help`
138+
For complete documentation please run `intezer-analyze upload-endpoint-scans-in-directory --help`
139139

140140
## Upload all subdirectories with .eml files to analyze
141141
Upload a directory with .eml files
142142

143143
### Parameter
144-
UPLOAD_EMAILS_IN_DIRECTORY: Path to root directory containing the .eml fiels
144+
UPLOAD_EMAILS_IN_DIRECTORY: Path to root directory containing the .eml files
145145

146146
### Examples:
147-
$ intezer-analyze upload_emails_in_directory /path/to/emails_root_directory
147+
$ intezer-analyze upload-emails-in-directory /path/to/emails_root_directory
148148

149149
# Troubleshooting
150150
The cli produce a log file named `intezer-analyze-cli.log` in the current working directory.

intezer_analyze_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.11.3'
1+
__version__ = '1.12.0'

intezer_analyze_cli/cli.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
logger = logging.getLogger('intezer_cli')
1818

1919

20+
class AliasedGroup(click.Group):
21+
def get_command(self, ctx, cmd_name):
22+
rv = click.Group.get_command(self, ctx, cmd_name)
23+
if rv is not None:
24+
return rv
25+
matches = [x for x in self.list_commands(ctx)
26+
if x.replace('-', '_') == cmd_name.replace('-', '_')]
27+
if not matches:
28+
return None
29+
elif len(matches) == 1:
30+
return click.Group.get_command(self, ctx, matches[0])
31+
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
32+
33+
def resolve_command(self, ctx, args):
34+
# always return the full command name
35+
_, cmd, args = super().resolve_command(ctx, args)
36+
return cmd.name, cmd, args
37+
38+
2039
def create_global_api():
2140
try:
2241
api_key = key_store.get_stored_api_key()
@@ -41,7 +60,7 @@ def create_global_api():
4160
raise click.Abort()
4261

4362

44-
@click.group(context_settings=dict(help_option_names=['-h', '--help'], max_content_width=120),
63+
@click.group(cls=AliasedGroup, context_settings=dict(help_option_names=['-h', '--help'], max_content_width=120),
4564
help=f'Intezer Labs Ltd. Intezer Analyze CLI {__version__}')
4665
def main_cli():
4766
pass
@@ -135,7 +154,7 @@ def analyze(path: str,
135154
f'and attach the log file in {utilities.log_file_path}')
136155

137156

138-
@main_cli.command('analyze_by_list', short_help='Send a text file with list of hashes')
157+
@main_cli.command('analyze-by-list', short_help='Send a text file with list of hashes')
139158
@click.argument('path', type=click.Path(exists=True, dir_okay=False))
140159
def analyze_by_list(path):
141160
""" Send a text file with hashes for analysis in Intezer Analyze.
@@ -146,7 +165,7 @@ def analyze_by_list(path):
146165
\b
147166
Examples:
148167
Send txt file with hashes for analysis:
149-
$ intezer-analyze analyze_by_list ~/files/hashes.txt
168+
$ intezer-analyze analyze-by-list ~/files/hashes.txt
150169
"""
151170
try:
152171
create_global_api()
@@ -159,8 +178,7 @@ def analyze_by_list(path):
159178
click.echo('Unexpected error occurred, please contact us at support@intezer.com '
160179
f'and attach the log file in {utilities.log_file_path}')
161180

162-
163-
@main_cli.command('index_by_list', short_help='Send a text file with list of hashes, verdict, family name if malicious')
181+
@main_cli.command('index-by-list', short_help='Send a text file with list of hashes, verdict, family name if malicious')
164182
@click.argument('path', type=click.Path(exists=True, dir_okay=False))
165183
@click.option('--index-as', type=click.Choice(['malicious', 'trusted'], case_sensitive=True))
166184
@click.argument('family_name', required=False, type=click.STRING, default=None)
@@ -173,7 +191,7 @@ def index_by_list(path: str, index_as: str, family_name: str):
173191
174192
\b
175193
Examples:
176-
$ intezer-analyze index_by_list ~/files/hashes.txt malicious family_name
194+
$ intezer-analyze index-by-list ~/files/hashes.txt malicious family_name
177195
\b
178196
"""
179197
try:
@@ -193,7 +211,6 @@ def index_by_list(path: str, index_as: str, family_name: str):
193211
click.echo('Unexpected error occurred, please contact us at support@intezer.com '
194212
f'and attach the log file in {utilities.log_file_path}')
195213

196-
197214
@main_cli.command('index', short_help='index a file or a directory')
198215
@click.argument('path', type=click.Path(exists=True))
199216
@click.option('--index-as', type=click.Choice(['malicious', 'trusted'], case_sensitive=True))
@@ -239,7 +256,7 @@ def index(path: str, index_as: str, family_name: str, ignore_directory_count_lim
239256
f'and attach the log file in {utilities.log_file_path}')
240257

241258

242-
@main_cli.command('upload_endpoint_scan', short_help='upload a directory with offline endpoint scan results')
259+
@main_cli.command('upload-endpoint-scan', short_help='upload a directory with offline endpoint scan results')
243260
@click.argument('offline_scan_directory', type=click.Path(exists=True))
244261
@click.option('--force', is_flag=True, default=False, help='Upload scan even if it was already uploaded')
245262
@click.option('--max-concurrent', default=0, type=int, help='Maximum number of concurrent uploads.')
@@ -253,7 +270,7 @@ def upload_endpoint_scan(offline_scan_directory: str, force: bool, max_concurren
253270
Examples:
254271
upload a directory with offline endpoint scan results:
255272
256-
$ intezer-analyze upload_endpoint_scan /path/to/endpoint_scan_results
273+
$ intezer-analyze upload-endpoint-scan /path/to/endpoint_scan_results
257274
"""
258275
try:
259276
create_global_api()
@@ -267,9 +284,8 @@ def upload_endpoint_scan(offline_scan_directory: str, force: bool, max_concurren
267284
click.echo('Unexpected error occurred, please contact us at support@intezer.com '
268285
f'and attach the log file in {utilities.log_file_path}')
269286

270-
271-
@main_cli.command('upload_endpoint_scans_in_directory',
272-
short_help='upload all subdirectories with offline endpoint scan results')
287+
@main_cli.command('upload-endpoint-scans-in-directory',
288+
short_help='upload all subdirectories with offline endpoint scan results')
273289
@click.argument('offline_scans_root_directory', type=click.Path(exists=True))
274290
@click.option('--force', is_flag=True, default=False, help='Upload scans even if they were already uploaded')
275291
@click.option('--max-concurrent', default=0, type=int, help='Maximum number of concurrent uploads.')
@@ -283,7 +299,7 @@ def upload_endpoint_scans_in_directory(offline_scans_root_directory: str, force:
283299
Examples:
284300
upload a directory with offline endpoint scan results:
285301
286-
$ intezer-analyze upload_endpoint_scans_in_directory /path/to/endpoint_scan_results_root
302+
$ intezer-analyze upload-endpoint-scans-in-directory /path/to/endpoint_scan_results_root
287303
"""
288304
try:
289305
create_global_api()
@@ -297,9 +313,8 @@ def upload_endpoint_scans_in_directory(offline_scans_root_directory: str, force:
297313
click.echo('Unexpected error occurred, please contact us at support@intezer.com '
298314
f'and attach the log file in {utilities.log_file_path}')
299315

300-
301-
@main_cli.command('upload_emails_in_directory',
302-
short_help='upload all subdirectories with .emal files')
316+
@main_cli.command('upload-emails-in-directory',
317+
short_help='upload all subdirectories with .emal files')
303318
@click.argument('emails_root_directory', type=click.Path(exists=True, file_okay=False, dir_okay=True))
304319
@click.option('--ignore-directory-count-limit',
305320
is_flag=True,
@@ -314,7 +329,7 @@ def upload_emails_in_directory(emails_root_directory: str, ignore_directory_coun
314329
Examples:
315330
upload a directory with .eml files:
316331
317-
$ intezer-analyze upload_emails_in_directory /path/to/emails_root_directory
332+
$ intezer-analyze upload-emails-in-directory /path/to/emails_root_directory
318333
"""
319334
try:
320335
create_global_api()
@@ -327,11 +342,9 @@ def upload_emails_in_directory(emails_root_directory: str, ignore_directory_coun
327342
click.echo('Unexpected error occurred, please contact us at support@intezer.com '
328343
f'and attach the log file in {utilities.log_file_path}')
329344

330-
331345
if __name__ == '__main__':
332346
try:
333347
main_cli()
334-
335348
except Exception as e:
336349
logger.exception(f'Unexpected error occurred {e}')
337350
click.echo('Unexpected error occurred')

tests/unit/cli_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def test_index_by_txt_file_command_wrong_index(self):
370370

371371
# Assert
372372
self.assertEqual(result.exit_code, 2, result.exception)
373-
self.assertTrue(b'Usage: main-cli index_by_list [OPTIONS] PATH [FAMILY_NAME]' in result.stdout_bytes)
374-
self.assertTrue(b'Try \'main-cli index_by_list -h\' for help.' in result.stdout_bytes)
373+
self.assertTrue(b'Usage: main-cli index-by-list [OPTIONS] PATH [FAMILY_NAME]' in result.stdout_bytes)
374+
self.assertTrue(b'Try \'main-cli index-by-list -h\' for help.' in result.stdout_bytes)
375375
self.assertTrue(b'Error: Invalid value for \'--index-as\': invalid choice: wrong_index_name. '
376376
b'(choose from malicious, trusted)' in result.stdout_bytes)

0 commit comments

Comments
 (0)