Commit c1f19851 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli: Log fully quoted command line



Instead of logging the concatenated arguments, with this patch every
command will properly quote its full command line. This makes it easier
to just copy-and-paste commands from “commands.log” to re-run them. Also
remove a case of “x = a or b” for non-boolean values.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 5b3f5fc8
......@@ -2151,15 +2151,19 @@ def GenericMain(commands, override=None, aliases=None,
"""
# save the program name and the entire command line for later logging
if sys.argv:
binary = os.path.basename(sys.argv[0]) or sys.argv[0]
binary = os.path.basename(sys.argv[0])
if not binary:
binary = sys.argv[0]
if len(sys.argv) >= 2:
binary += " " + sys.argv[1]
old_cmdline = " ".join(sys.argv[2:])
logname = utils.ShellQuoteArgs([binary, sys.argv[1]])
else:
old_cmdline = ""
logname = binary
cmdline = utils.ShellQuoteArgs([binary] + sys.argv[1:])
else:
binary = "<unknown program>"
old_cmdline = ""
cmdline = "<unknown>"
if aliases is None:
aliases = {}
......@@ -2178,13 +2182,10 @@ def GenericMain(commands, override=None, aliases=None,
for key, val in override.iteritems():
setattr(options, key, val)
utils.SetupLogging(constants.LOG_COMMANDS, binary, debug=options.debug,
utils.SetupLogging(constants.LOG_COMMANDS, logname, debug=options.debug,
stderr_logging=True)
if old_cmdline:
logging.info("run with arguments '%s'", old_cmdline)
else:
logging.info("run with no arguments")
logging.info("Command line: %s", cmdline)
try:
result = func(options, args)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment