Skip to content

Commit 740ee32

Browse files
reckless: redirect help alias output when --json option is used
This doesn't change the argparse behavior with --help/-h, but it does correct the output in this one case where we must manually call it.
1 parent 3c0fec0 commit 740ee32

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tools/reckless

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import argparse
55
import copy
66
import datetime
77
from enum import Enum
8+
import io
89
import json
910
import logging
1011
import os
@@ -1124,9 +1125,16 @@ INSTALLERS = [pythonuv, pythonuvlegacy, python3venv, poetryvenv,
11241125

11251126
def help_alias(targets: list):
11261127
if len(targets) == 0:
1127-
parser.print_help(sys.stdout)
1128+
if log.capture:
1129+
help_output = io.StringIO()
1130+
parser.print_help(help_output)
1131+
log.add_result(help_output.getvalue())
1132+
else:
1133+
parser.print_help(sys.stdout)
11281134
else:
11291135
log.info('try "reckless {} -h"'.format(' '.join(targets)))
1136+
if log.capture:
1137+
log.reply_json()
11301138
sys.exit(1)
11311139

11321140

@@ -2078,7 +2086,9 @@ if __name__ == '__main__':
20782086

20792087
if 'targets' in args: # and len(args.targets) > 0:
20802088
if args.func.__name__ == 'help_alias':
2081-
args.func(args.targets)
2089+
log.add_result(args.func(args.targets))
2090+
if log.capture:
2091+
log.reply_json()
20822092
sys.exit(0)
20832093
# Catch a missing argument so that we can overload functions.
20842094
if len(args.targets) == 0:

0 commit comments

Comments
 (0)