scripts: Added -Q/--query as alternative to --total

This better matches the runners' new -Q/--query-define flag, and, thanks
to some argparse trickery, is simpler implementation wise.

Example:

  $ ./scripts/code.py lfs3.o -Qsize
      66570

  $ ./scripts/stack.py -Qlimit lfs3.ci
       3312

The only downside is this takes the --small-table shortform flag, but
--small-table doesn't really need a shortform flag.
This commit is contained in:
Christopher Haster
2026-02-12 19:13:53 -06:00
parent cb91b6b2a6
commit 93c85870e8
10 changed files with 257 additions and 154 deletions
+32 -17
View File
@@ -2264,26 +2264,14 @@ def table(Result, results, diff_results=None, *,
small_header=False,
no_total=False,
small_total=False,
small_table=False,
summary=False,
total=False,
**_):
import builtins
all_, all = all, builtins.all
# small_table implies small_header + no_total or small_total
if small_table:
small_header = True
small_total = True
no_total = no_total or (not summary and not total)
# summary implies small_header
if summary:
small_header = True
# total implies summary + no_header + small_total
if total:
summary = True
no_header = True
small_total = True
if by is None:
by = Result._by
@@ -3326,6 +3314,24 @@ if __name__ == "__main__":
)(*x.split('=', 1)),
help="Like -f/--field, but hidden from the table renderer, "
"and doesn't affect -f/--field defaults.")
class AppendQuery(argparse.Action):
def __call__(self, parser, namespace, value, option):
if namespace.fields is None:
namespace.fields = []
namespace.fields.append((value, False))
namespace.summary = True
namespace.no_header = True
namespace.small_total = True
parser.add_argument(
'-Q', '--query',
action=AppendQuery,
type=lambda x: (
lambda k, v=None: (
k.strip(),
CsvExpr(v) if v is not None else None)
)(*x.split('=', 1)),
help="Like -f/--field, but also implies --total. Useful for "
"scripting.")
parser.add_argument(
'-D', '--define',
dest='defines',
@@ -3458,17 +3464,26 @@ if __name__ == "__main__":
'--small-total',
action='store_true',
help="Don't show TOTAL name.")
class StoreSmallTable(argparse._StoreTrueAction):
def __call__(self, parser, namespace, value, option):
namespace.small_header = True
namespace.no_total = True
parser.add_argument(
'-Q', '--small-table',
action='store_true',
help="Equivalent to --small-header + --no-total or --small-total.")
'--small-table',
action=StoreSmallTable,
help="Equivalent to --small-header + --no-total.")
parser.add_argument(
'-Y', '--summary',
action='store_true',
help="Only show the total.")
class StoreTotal(argparse._StoreTrueAction):
def __call__(self, parser, namespace, value, option):
namespace.summary = True
namespace.no_header = True
namespace.small_total = True
parser.add_argument(
'-t', '--total',
action='store_true',
'--total',
action=StoreTotal,
help="Equivalent to --summary + --no-header + --small-total. "
"Useful for scripting.")
parser.add_argument(