Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Duf <chris@openmarl.org>
  • Loading branch information
pillo79 and dottspina authored Mar 11, 2024
1 parent c73481f commit 3289dc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
12 changes: 7 additions & 5 deletions doc/site/src/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ Where:
Batch Mode
==========

DTSh can also be used non-interactively, by passing a series of commands to
execute at startup or a file containing such commands. This is useful for
scripting and automation. In addition, the ``-i --interactive`` option permits
to enter the interactive loop after the batch commands have been executed.
For scripting and automation, DTSh can also be used non-interactively by passing:

- a series of commands to execute at startup: ``-c CMD1 -c CMD2``
- or a file containing such commands: ``-f FILE``

The ``-i --interactive`` option then permits to enter the interactive loop after the batch commands have been executed.

For example, to list the contents of the root of the devicetree and then change
to another directory, before entering the interactive loop, you can use the
Expand All @@ -294,7 +296,7 @@ following command:
.. code-block:: none
$ dtsh -c "ls -l" -c "cd &i2c0" -i
dtsh (0.2.0): A Devicetree Shell
dtsh (0.2.1): A Devicetree Shell
How to exit: q, or quit, or exit, or press Ctrl-D
> Name Labels Binding
Expand Down
11 changes: 5 additions & 6 deletions src/dtsh/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,17 @@ def batch_source(self) -> Optional[Union[str, List[str]]]:
"""Batch command source, if defined."""
if self._argv.c:
return cast(List[str], self._argv.c)
elif self._argv.f:
return self._argv.f
else:
return None
if self._argv.f:
return cast(str, self._argv.f)
return None

@property
def interactive(self) -> bool:
"""Is the interactive loop requested?"""
if not self._argv.c and not self._argv.f:
if not (self._argv.c or self._argv.f):
# no batch input, must be interactive
return True
return self._argv.interactive
return cast(bool, self._argv.interactive)


def _load_preference_file(path: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/dtsh/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,6 @@ def readline(self, multi_prompt: Optional[Sequence[Any]] = None) -> str:
"""Overrides DTShInput.readline()."""
if self._cmds:
line: str = self._cmds.pop(0)
return line.rstrip()
return line

raise EOFError()
2 changes: 1 addition & 1 deletion src/dtsh/rich/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def create_batch(
# Batch commands from cli arguments.
batch_is = DTShInputCmds(batch)
else:
raise NotImplementedError("create_batch({})".format(repr(type(batch))))
raise NotImplementedError(f"create_batch({repr(type(batch))})")

dt = cls._create_dtmodel(dts_path, binding_dirs)
vt = DTShBatchRichVT(batch_is, interactive)
Expand Down

0 comments on commit 3289dc3

Please sign in to comment.