Wire up -o for stories; remove -o from status
- Extract _add_output_arg() helper; add it explicitly to summary, csv, and stories subparsers (removes it implicitly from status) - _cmd_stories now honours args.output, redirecting print_stories output to the given file (same pattern as _cmd_summary) - Update README with stories -o example
This commit is contained in:
parent
cd8ca789aa
commit
0204accd05
2 changed files with 19 additions and 1 deletions
|
|
@ -76,6 +76,7 @@ uv run timesheets csv -w --raw --joplin # full week, no aggregation
|
|||
```sh
|
||||
uv run timesheets stories --joplin # today
|
||||
uv run timesheets stories -w --joplin # full week
|
||||
uv run timesheets stories -w --joplin -o stories.md # write to file
|
||||
```
|
||||
|
||||
### status
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ def _add_shared_args(parser: argparse.ArgumentParser) -> None:
|
|||
),
|
||||
default=None,
|
||||
)
|
||||
|
||||
|
||||
def _add_output_arg(parser: argparse.ArgumentParser) -> None:
|
||||
"""Add the -o/--output argument to a subparser."""
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--output",
|
||||
|
|
@ -109,6 +113,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|||
help="Print a human-readable summary of time spent per project.",
|
||||
)
|
||||
_add_shared_args(summary_parser)
|
||||
_add_output_arg(summary_parser)
|
||||
summary_parser.add_argument(
|
||||
"--weekly",
|
||||
"-w",
|
||||
|
|
@ -132,6 +137,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|||
help="Export timesheet entries as CSV.",
|
||||
)
|
||||
_add_shared_args(csv_parser)
|
||||
_add_output_arg(csv_parser)
|
||||
csv_parser.add_argument(
|
||||
"--raw",
|
||||
action="store_true",
|
||||
|
|
@ -160,6 +166,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|||
help="List stories worked on, grouped by project.",
|
||||
)
|
||||
_add_shared_args(stories_parser)
|
||||
_add_output_arg(stories_parser)
|
||||
stories_parser.add_argument(
|
||||
"--weekly",
|
||||
"-w",
|
||||
|
|
@ -399,7 +406,17 @@ def _cmd_stories(args: argparse.Namespace, config: dict) -> None:
|
|||
return
|
||||
|
||||
project_map = _resolve_project_map(args, config)
|
||||
print_stories(rows, project_map)
|
||||
if args.output:
|
||||
with open(args.output, "w", encoding="utf-8") as f:
|
||||
old_stdout = sys.stdout
|
||||
sys.stdout = f
|
||||
try:
|
||||
print_stories(rows, project_map)
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
print(f"Written to {args.output}", file=sys.stderr)
|
||||
else:
|
||||
print_stories(rows, project_map)
|
||||
|
||||
|
||||
def _cmd_csv(args: argparse.Namespace, config: dict) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue