Skip to content

Commit

Permalink
Fix user provided default run and variation for cat command
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jun 27, 2024
1 parent d9675a5 commit f4573ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 12 additions & 2 deletions python/ccdb/cmd/commands/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def process_arguments(self, args):

parser.add_argument("-d", "--directory")
parser.add_argument("-v", "--variation")
parser.add_argument("-a", "--ass-id")
parser.add_argument("-a", "--id")
parser.add_argument("-r", "--run")
parser.add_argument("-f", "--file")
parser.add_argument("-ph", "--horizontal", action="store_true", dest='user_request_print_horizontal')
Expand All @@ -159,6 +159,16 @@ def process_arguments(self, args):
# it probably must be a request or just a table name
result.request = parse_request(result.obj_name)

# Check if user set the default variation
if not result.request.variation_is_parsed and self.context.current_variation:
result.request.variation = self.context.current_variation
result.request.variation_is_parsed = True

# Check if user set the default run
if not result.request.run_is_parsed and self.context.current_run:
result.request.run = self.context.current_run
result.request.run_is_parsed = True

return result

# ----------------------------------------
Expand Down Expand Up @@ -410,7 +420,7 @@ def print_help(self):
Usage:
cat <request or table path>
cat --id <assignment_id> #Where assignment_id provided by 'vers <table path>' command
cat -a <assignment_id> #Where assignment_id provided by 'vers <table path>' command
Formatting flags:
Expand Down
13 changes: 13 additions & 0 deletions python/tests/integ_test_cli_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ def test_cat(self):
self.cli.process_command_line("cat /test/test_vars/test_table")
self.assertIn("2.3", self.output.getvalue())

def test_cat_user_set_variation(self):
"""In non-interactive mode, cat should handle path without leading / as absolute anyway"""

# Test DB has a test data assignment for:
# variation: test
# runs: 500-2000
# it has data: [[4,6,8],[10,12,13]]
self.cli.context.current_variation = "test"
self.cli.context.current_run = 600
self.cli.process_command_line("cat /test/test_vars/test_table")
self.assertIn("13", self.output.getvalue())


def test_cat_not_abs_path(self):
"""In non-interactive mode, cat should handle path without leading / as absolute anyway"""
self.cli.process_command_line("cat test/test_vars/test_table")
Expand Down

0 comments on commit f4573ce

Please sign in to comment.