Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to override CSV default header detection. #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added option to override csv header detection

### Changed

- Rich-CLI now assumes that the input file is encoded in UTF-8 https://github.com/Textualize/rich-cli/pull/56
Expand Down
8 changes: 7 additions & 1 deletion src/rich_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class OptionHighlighter(RegexHighlighter):
@click.option("--ipynb", is_flag=True, help="Display [u]Jupyter notebook[/u].")
@click.option("--syntax", is_flag=True, help="[u]Syntax[/u] highlighting.")
@click.option("--inspect", is_flag=True, help="[u]Inspect[/u] a python object.")
@click.option("--header", type=bool, metavar="BOOL", default=None, help="Overrides the CSV [u]header[/u] detection (requires --csv).")
@click.option(
"--head",
"-h",
Expand Down Expand Up @@ -410,6 +411,7 @@ def main(
csv: bool = False,
ipynb: bool = False,
inspect: bool = True,
header: Optional[bool] = None,
emoji: bool = False,
left: bool = False,
right: bool = False,
Expand Down Expand Up @@ -607,7 +609,7 @@ def print_usage() -> None:

elif resource_format == CSV:

renderable = render_csv(resource, head, tail, title, caption)
renderable = render_csv(resource, head, tail, title, caption, header)

elif resource_format == IPYNB:

Expand Down Expand Up @@ -739,6 +741,7 @@ def render_csv(
tail: Optional[int] = None,
title: Optional[str] = None,
caption: Optional[str] = None,
header: Optional[bool] = None,
) -> RenderableType:
"""Render resource as CSV.

Expand Down Expand Up @@ -771,6 +774,9 @@ def render_csv(
has_header = True
else:
on_error(str(error))
finally:
if header is not None:
has_header = header

csv_file = io.StringIO(csv_data)
reader = csv.reader(csv_file, dialect=dialect)
Expand Down