Skip to content

Commit

Permalink
Fix cat command relative path work in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jul 1, 2024
1 parent de7b7d8 commit c30128d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/ccdb/cmd/commands/cat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import posixpath
import sys
import os

Expand Down Expand Up @@ -100,10 +101,13 @@ def get_assignment_by_request(self, request):
@type request: ParseRequestResult
"""

# If we are in interactive or test mode, and path is not absolute, combine current path and provided path
if not request.path.startswith('/') and self.context.current_path:
request.path = posixpath.join(self.context.current_path, request.path)

# In non-interactive mode, cat should handle path without leading / as absolute anyway
# Check mode and if relative path is given
path_check_needed = not self.context.is_interactive or self.context.current_path in ["/", ""]
if path_check_needed and request.path_is_parsed and not request.path.startswith("/"):
if request.path_is_parsed and not request.path.startswith("/"):
# PatCH the PaTH
request.path = "/" + request.path

Expand Down
8 changes: 8 additions & 0 deletions python/tests/integ_test_cli_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ 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_interactive(self):
"""cat. Return constants"""
# in interactive mode it should also work if the path is absolute
self.cli.context.is_interactive = True
self.cli.context.current_path = 'test/test_vars/'
self.cli.process_command_line("cat test_table")
self.assertIn("2.3", self.output.getvalue())

def test_cat_by_id(self):
"""cat. Return """
self.cli.process_command_line("cat -a 2")
Expand Down

0 comments on commit c30128d

Please sign in to comment.