diff --git a/doc/cephfs/cephfs-shell.rst b/doc/cephfs/cephfs-shell.rst index 3825598fa49..2d4c36d5fd1 100644 --- a/doc/cephfs/cephfs-shell.rst +++ b/doc/cephfs/cephfs-shell.rst @@ -238,18 +238,21 @@ Usage: * name - name of the alias being looked up, added, or replaced * value - what the alias will be resolved to (if adding or replacing) this can contain spaces and does not need to be quoted -pyscript --------- +run_pyscript +------------ Runs a python script file inside the console Usage: - pyscript [script_arguments] + run_pyscript [script_arguments] * Console commands can be executed inside this script with cmd ("your command") - However, you cannot run nested "py" or "pyscript" commands from within this script - Paths or arguments that contain spaces must be enclosed in quotes + However, you cannot run nested "py" or "pyscript" commands from within this + script. Paths or arguments that contain spaces must be enclosed in quotes + +.. note:: This command is available as ``pyscript`` for cmd2 versions 0.9.13 + or less. py -- @@ -328,18 +331,21 @@ Usage: * file_path - path to a file to open in editor -load ----- +run_script +---------- Runs commands in script file that is encoded as either ASCII or UTF-8 text. +Each command in the script should be separated by a newline. Usage: - load + run_script + * file_path - a file path pointing to a script -* Script should contain one command per line, just like command would betyped in console. +.. note:: This command is available as ``load`` for cmd2 versions 0.9.13 + or less. shell ----- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 7dd1fe17ad9..60bd7f5e1e4 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -5,7 +5,6 @@ import argparse import os import os.path import sys -from cmd2 import Cmd import cephfs as libcephfs import shutil import traceback @@ -16,6 +15,10 @@ import re import shlex import stat +from cmd2 import Cmd +from cmd2 import __version__ as cmd2_version +from distutils.version import LooseVersion + if sys.version_info.major < 3: raise RuntimeError("cephfs-shell is only compatible with python3") @@ -1332,7 +1335,10 @@ if __name__ == '__main__': if args.config: config_file = args.config if args.batch: - args.commands = ['load ' + args.batch, ',quit'] + if LooseVersion(cmd2_version) <= LooseVersion("0.9.13"): + args.commands = ['load ' + args.batch, ',quit'] + else: + args.commands = ['run_script ' + args.batch, ',quit'] if args.test: args.commands.extend(['-t,'] + [arg + ',' for arg in args.test]) sys.argv.clear()