Skip to content

Commit

Permalink
Rename constants
Browse files Browse the repository at this point in the history
  • Loading branch information
twiggler committed Oct 7, 2024
1 parent 754b57e commit afc3150
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions dissect/target/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ExtendedCmd(cmd.Cmd):

CMD_PREFIX = "cmd_"
_runtime_aliases = {}
DEFAULT_RUNCOMMANDSFILE = None
DEFAULT_RUNCOMMANDS_FILE = None

def __init__(self, cyber: bool = False):
cmd.Cmd.__init__(self)
Expand Down Expand Up @@ -136,13 +136,12 @@ def _load_targetrc(self, path: pathlib.Path) -> None:
log.debug("Error processing .targetrc file: %s", e)

Check warning on line 136 in dissect/target/tools/shell.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/tools/shell.py#L135-L136

Added lines #L135 - L136 were not covered by tests

def _get_targetrc_path(self) -> Optional[pathlib.Path]:
"""Get the path to the run commands file. Can return None if DEFAULT_RUNCOMMANDSFILE is not set."""
return pathlib.Path(self.DEFAULT_RUNCOMMANDSFILE).expanduser() if self.DEFAULT_RUNCOMMANDSFILE else None
"""Get the path to the run commands file. Can return ``None`` if ``DEFAULT_RUNCOMMANDS_FILE`` is not set."""
return pathlib.Path(self.DEFAULT_RUNCOMMANDS_FILE).expanduser() if self.DEFAULT_RUNCOMMANDS_FILE else None

Check warning on line 140 in dissect/target/tools/shell.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/tools/shell.py#L140

Added line #L140 was not covered by tests

def preloop(self) -> None:
super().preloop()
targetrc_path = self._get_targetrc_path()
if targetrc_path is not None:
if targetrc_path := self._get_targetrc_path():
self._load_targetrc(targetrc_path)

@staticmethod
Expand Down Expand Up @@ -333,8 +332,8 @@ class TargetCmd(ExtendedCmd):
DEFAULT_HISTFILESIZE = 10_000
DEFAULT_HISTDIR = None
DEFAULT_HISTDIRFMT = ".dissect_history_{uid}_{target}"
DEFAULT_RUNCOMMANDSFILE = "~/.targetrc"
CONFIG_KEY_RUNCOMMANDSFILE = "TARGETRCFILE"
DEFAULT_RUNCOMMANDS_FILE = "~/.targetrc"
CONFIG_KEY_RUNCOMMANDS_FILE = "TARGETRCFILE"

def __init__(self, target: Target):
self.target = target
Expand Down Expand Up @@ -368,7 +367,7 @@ def _get_targetrc_path(self) -> pathlib.Path:
"""Get the path to the run commands file."""

return pathlib.Path(
getattr(self.target._config, self.CONFIG_KEY_RUNCOMMANDSFILE, self.DEFAULT_RUNCOMMANDSFILE)
getattr(self.target._config, self.CONFIG_KEY_RUNCOMMANDS_FILE, self.DEFAULT_RUNCOMMANDS_FILE)
).expanduser()

def preloop(self) -> None:
Expand Down Expand Up @@ -1178,8 +1177,8 @@ class RegistryCli(TargetCmd):
"""CLI for browsing the registry."""

# Registry shell is incompatible with default shell, so override the default rc file and config key
DEFAULT_RUNCOMMANDSFILE = "~/.targetrc.registry"
CONFIG_KEY_RUNCOMMANDSFILE = "TARGETRCFILE_REGISTRY"
DEFAULT_RUNCOMMANDS_FILE = "~/.targetrc.registry"
CONFIG_KEY_RUNCOMMANDS_FILE = "TARGETRCFILE_REGISTRY"

def __init__(self, target: Target, registry: regutil.RegfHive | None = None):
self.prompt_base = _target_name(target)
Expand Down

0 comments on commit afc3150

Please sign in to comment.