Skip to content

Add support for overriding configuration via command line arguments - #2

Open
alexwoo-awso wants to merge 1 commit into
aiv:mainfrom
alexwoo-awso:add-cli-overrides
Open

Add support for overriding configuration via command line arguments#2
alexwoo-awso wants to merge 1 commit into
aiv:mainfrom
alexwoo-awso:add-cli-overrides

Conversation

@alexwoo-awso

Copy link
Copy Markdown

Changes

Adds support for overriding .env configuration via command-line arguments in fetch_invoices.py and documents it in README.md.

Key improvements:

  • CLI args take precedence over env vars (falls back gracefully if not provided).
  • No breaking changes—existing .env-only usage works unchanged.

Added Arguments

python fetch_invoices.py --token YOUR_TOKEN --nip 1234567890 [--format json]

- `--token`: Overrides `KSEF_TOKEN` from `.env`.
- `--nip`: Overrides `CONTEXT_NIP` from `.env`.
- `--format`: Output format (`json` default or `text`).

Code Changes

fetch_invoices.py (13 additions, 5 deletions):

  • Updated main(): Load dotenv first, then override with args.token or os.getenv('KSEF_TOKEN').
  • Added argparse for --token and --nip with Polish help text.
  • Error handling preserved for missing config.

README.md (13 additions, 0 deletions):

  • New section: "Nadpisywanie konfiguracji" with usage example and param list.

Usage Examples

With overrides (no .env needed):

python fetch_invoices.py --token twój-token-ksef --nip 1234567890 --format text

With partial overrides:

python fetch_invoices.py --token twój-token-ksef --format json  # Uses .env NIP

Output unchanged: JSON or text summary of fetched invoices.

Testing
Verified: Args override env; fallback works; formats preserved.

No impact on core logic (auth, fetch, decrypt, dedup). Ready to merge.

Feedback welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant