Skip to content

Commit

Permalink
Merge pull request #815 from buildtesters/no_header
Browse files Browse the repository at this point in the history
add option 'buildtest history list --no-header' to toggle output of columns in terse output
  • Loading branch information
shahzebsiddiqui authored Jul 19, 2021
2 parents 5b7c4ac + af8e193 commit 07e6b46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _test_name ()

_history_id ()
{
buildtest history list -t | cut -d '|' -f 1 | sort -g
buildtest history list -t -n | cut -d '|' -f 1 | sort -g
}
# entry point to buildtest bash completion function
_buildtest ()
Expand Down Expand Up @@ -83,7 +83,7 @@ _buildtest ()
;;

report)
local opts="-h --help --helpformat --helpfilter --format --filter --latest --oldest -r --report clear"
local opts="-h --help --helpformat --helpfilter --format --filter --latest --oldest -r --report clear -t --terse"
COMPREPLY=( $( compgen -W "$opts" -- $cur ) );;

config)
Expand Down Expand Up @@ -164,7 +164,7 @@ _buildtest ()

case ${COMP_WORDS[2]} in
list)
local opts="-h --help -t --terse"
local opts="-h --help -t --terse -n --no-header"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
query)
local opts="-h --help -l --log"
Expand Down
6 changes: 6 additions & 0 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def history_menu(subparsers):
help="Print output in machine readable format",
)

list_parser.add_argument(
"-n",
"--no-header",
action="store_true",
help="Do not print header columns in terse output (--terse)",
)
query = history_subparser.add_parser(
"query", help="Query information for a particular build"
)
Expand Down
17 changes: 15 additions & 2 deletions buildtest/cli/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_history(args):
"""This is the entry point for command ``buildtest build history`` command which reports"""

if args.history == "list":
list_builds(terse=args.terse)
list_builds(header=args.no_header, terse=args.terse)

if args.history == "query":
query_builds(build_id=args.id, log_option=args.log)
Expand All @@ -29,7 +29,16 @@ def sorted_alphanumeric(data):
return sorted(data, key=alphanum_key)


def list_builds(terse=None):
def list_builds(header=None, terse=None):
"""This method is entry point for ``buildtest history list`` which prints all previous builds
stored in **BUILD_HISTORY_DIR**. Each directory has a ``build.json`` file that stores content
of each build that was run by ``buildtest build``.
:param header: Control whether header columns are displayed with terse format
:type header: bool, optional
:param terse: Print output in terse format
:type terse: bool, optional
"""

history_files = walk_tree(BUILD_HISTORY_DIR, ".json")
logger.debug(f"Searching for all '.json' files in directory: {BUILD_HISTORY_DIR}")
Expand Down Expand Up @@ -73,6 +82,10 @@ def list_builds(terse=None):

if terse:

# We print the table columns if --no-header is not specified
if not header:
print("|".join(table.keys()))

for (
build_id,
hostname,
Expand Down

0 comments on commit 07e6b46

Please sign in to comment.