Skip to content

Commit

Permalink
add gita info set-length subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
nosarthur committed Jun 13, 2024
1 parent 6ce0174 commit 73d686d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
20 changes: 20 additions & 0 deletions gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ def f_info(args: argparse.Namespace):
with open(csv_config, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(to_display)
elif cmd == "set-length":
csv_config = common.get_config_fname("layout.csv")
print(f"Settings are in {csv_config}")
defaults = {

Check warning on line 153 in gita/__main__.py

View check run for this annotation

Codecov / codecov/patch

gita/__main__.py#L150-L153

Added lines #L150 - L153 were not covered by tests
"branch": 19,
"symbols": 5,
"branch_name": 27,
"commit_msg": 0,
"commit_time": 0, # 0 means no limit
"path": 30,
}
with open(csv_config, "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=defaults)
writer.writeheader()
writer.writerow(defaults)

Check warning on line 164 in gita/__main__.py

View check run for this annotation

Codecov / codecov/patch

gita/__main__.py#L161-L164

Added lines #L161 - L164 were not covered by tests


def f_clone(args: argparse.Namespace):
Expand Down Expand Up @@ -616,6 +631,11 @@ def main(argv=None):
info_cmds.add_parser("rm", description="Disable information item.").add_argument(
"info_item", choices=info.ALL_INFO_ITEMS, help="information item to delete"
)
info_cmds.add_parser(
"set-length",
description="Set default column widths for information items. "
"The settings are in layout.csv",
)

ll_doc = f""" status symbols:
+: staged changes
Expand Down
17 changes: 11 additions & 6 deletions gita/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Truncate:
exist or the requested field doesn't exist then don't
truncate
"""

widths = {}

def __init__(self):
Expand All @@ -25,17 +26,21 @@ def __init__(self):
reader = csv.DictReader(f)
self.widths = next(reader)

#Ensure the Dict type is Dict[str, int] to reduce casting elsewhere
for e in self.widths:
self.widths[e] = int(self.widths[e])
# Ensure the Dict type is Dict[str, int] to reduce casting elsewhere
for e, width in self.widths.items():
self.widths[e] = int(width)

Check warning on line 31 in gita/info.py

View check run for this annotation

Codecov / codecov/patch

gita/info.py#L30-L31

Added lines #L30 - L31 were not covered by tests

def truncate(self, field: str, message: str):
if field not in self.widths:
# 0 means no width limit applied
if not self.widths.get(field):
return message

length = 3 if self.widths[field] < 3 else self.widths[field]
return message[:length-3] + '...' if len(message) > length else message.ljust(length)

return (

Check warning on line 39 in gita/info.py

View check run for this annotation

Codecov / codecov/patch

gita/info.py#L39

Added line #L39 was not covered by tests
message[: length - 3] + "..."
if len(message) > length
else message.ljust(length)
)


class Color(Enum):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name="gita",
packages=["gita"],
version="0.16.7.1",
version="0.16.7.2",
license="MIT",
description="Manage multiple git repos with sanity",
long_description=long_description,
Expand Down

0 comments on commit 73d686d

Please sign in to comment.