mirror of
https://github.com/ceph/ceph
synced 2025-02-21 09:57:26 +00:00
Merge pull request #16359 from liewegas/wip-cli-stdinout
ceph: allow '-' with -i and -o for stdin/stdout Reviewed-by: Kefu Chai <kchai@redhat.com> Reviewed-by: Alfredo Deza <adeza@redhat.com>
This commit is contained in:
commit
81ae434c7f
@ -2326,6 +2326,12 @@ function test_mon_tell_help_command()
|
||||
expect_false ceph tell mon.zzz help
|
||||
}
|
||||
|
||||
function test_mon_stdin_stdout()
|
||||
{
|
||||
echo foo | ceph config-key put test_key -i -
|
||||
ceph config-key get test_key -o - | grep -c foo | grep -q 1
|
||||
}
|
||||
|
||||
function test_osd_tell_help_command()
|
||||
{
|
||||
ceph tell osd.1 help
|
||||
@ -2411,6 +2417,7 @@ MON_TESTS+=" mon_deprecated_commands"
|
||||
MON_TESTS+=" mon_caps"
|
||||
MON_TESTS+=" mon_cephdf_commands"
|
||||
MON_TESTS+=" mon_tell_help_command"
|
||||
MON_TESTS+=" mon_stdin_stdout"
|
||||
|
||||
OSD_TESTS+=" osd_bench"
|
||||
OSD_TESTS+=" osd_negative_filestore_merge_threshold"
|
||||
|
18
src/ceph.in
18
src/ceph.in
@ -264,9 +264,9 @@ def parse_cmdargs(args=None, target=''):
|
||||
parser.add_argument('-c', '--conf', dest='cephconf',
|
||||
help='ceph configuration file')
|
||||
parser.add_argument('-i', '--in-file', dest='input_file',
|
||||
help='input file')
|
||||
help='input file, or "-" for stdin')
|
||||
parser.add_argument('-o', '--out-file', dest='output_file',
|
||||
help='output file')
|
||||
help='output file, or "-" for stdout')
|
||||
|
||||
parser.add_argument('--id', '--user', dest='client_id',
|
||||
help='client id for authentication')
|
||||
@ -971,8 +971,11 @@ def main():
|
||||
inbuf = b''
|
||||
if parsed_args.input_file:
|
||||
try:
|
||||
with open(parsed_args.input_file, 'rb') as f:
|
||||
inbuf = f.read()
|
||||
if parsed_args.input_file == '-':
|
||||
inbuf = sys.stdin.read()
|
||||
else:
|
||||
with open(parsed_args.input_file, 'rb') as f:
|
||||
inbuf = f.read()
|
||||
except Exception as e:
|
||||
print('Can\'t open input file {0}: {1}'.format(parsed_args.input_file, e), file=sys.stderr)
|
||||
return 1
|
||||
@ -980,7 +983,10 @@ def main():
|
||||
# prepare output file, if any
|
||||
if parsed_args.output_file:
|
||||
try:
|
||||
outf = open(parsed_args.output_file, 'wb')
|
||||
if parsed_args.output_file == '-':
|
||||
outf = sys.stdout
|
||||
else:
|
||||
outf = open(parsed_args.output_file, 'wb')
|
||||
except Exception as e:
|
||||
print('Can\'t open output file {0}: {1}'.format(parsed_args.output_file, e), file=sys.stderr)
|
||||
return 1
|
||||
@ -1106,7 +1112,7 @@ def main():
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
if parsed_args.output_file:
|
||||
if parsed_args.output_file and parsed_args.output_file != '-':
|
||||
outf.close()
|
||||
|
||||
if final_ret:
|
||||
|
Loading…
Reference in New Issue
Block a user