Skip to content

Commit

Permalink
[CLI][Added] defs-from-env allows using environment vars for substitu…
Browse files Browse the repository at this point in the history
…tion

Closes #549
  • Loading branch information
set-soft committed Jan 8, 2024
1 parent 2ba5b71 commit 7c7d3af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `--help-list-offsets` to list footprint offsets (JLCPCB)
- `--help-list-rotations` to list footprint rotations (JLCPCB)
- `--stop-on-warnings` (`-W`) to stop on warnings (#545)
- `--defs-from-env` allows using environment vars for substitution (#549)
- Global options:
- `remove_solder_mask_for_dnp` similar to `remove_solder_paste_for_dnp` but
applied to the solder mask apertures. (#476)
Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuration/substitution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ files.

You can use ``-E`` as many times as you need.

Also note that the ``--def-from-env`` option adds all the environment
variables as definitions.

.. index::
pair: definitions; default
Expand Down
9 changes: 6 additions & 3 deletions docs/source/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ KiBot: KiCad automation tool for documents generation
Usage:
kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE]
[-q | -v...] [-L LOGFILE] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ...
[-E DEF] ... [-w LIST] [-D | -W] [--banner N] [TARGET...]
[-E DEF] ... [--defs-from-env] [-w LIST] [-D | -W] [--banner N]
[TARGET...]
kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] [--banner N]
[-E DEF] ... [--config-outs] [--only-pre|--only-groups] [--only-names]
[--output-name-first] --list
[-E DEF] ... [--defs-from-env] [--config-outs]
[--only-pre|--only-groups] [--only-names] [--output-name-first] --list
kibot [-v...] [-c PLOT_CONFIG] [--banner N] [-E DEF] ... [--only-names]
--list-variants
kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] [--banner N] --example
Expand Down Expand Up @@ -39,6 +40,8 @@ Options:
--config-outs Configure all outputs before listing them
-d OUT_DIR, --out-dir OUT_DIR The output directory [default: .]
-D, --dont-stop Try to continue if an output fails
--defs-from-env Use the environment vars as preprocessor
values
-e SCHEMA, --schematic SCHEMA The schematic file (.sch/.kicad_sch)
-E DEF, --define DEF Define preprocessor value (VAR=VAL)
-g DEF, --global-redef DEF Overwrite a global value (VAR=VAL)
Expand Down
11 changes: 8 additions & 3 deletions kibot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
Usage:
kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE]
[-q | -v...] [-L LOGFILE] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ...
[-E DEF] ... [-w LIST] [-D | -W] [--banner N] [TARGET...]
[-E DEF] ... [--defs-from-env] [-w LIST] [-D | -W] [--banner N]
[TARGET...]
kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] [--banner N]
[-E DEF] ... [--config-outs] [--only-pre|--only-groups] [--only-names]
[--output-name-first] --list
[-E DEF] ... [--defs-from-env] [--config-outs]
[--only-pre|--only-groups] [--only-names] [--output-name-first] --list
kibot [-v...] [-c PLOT_CONFIG] [--banner N] [-E DEF] ... [--only-names]
--list-variants
kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] [--banner N] --example
Expand Down Expand Up @@ -46,6 +47,8 @@
--config-outs Configure all outputs before listing them
-d OUT_DIR, --out-dir OUT_DIR The output directory [default: .]
-D, --dont-stop Try to continue if an output fails
--defs-from-env Use the environment vars as preprocessor
values
-e SCHEMA, --schematic SCHEMA The schematic file (.sch/.kicad_sch)
-E DEF, --define DEF Define preprocessor value (VAR=VAL)
-g DEF, --global-redef DEF Overwrite a global value (VAR=VAL)
Expand Down Expand Up @@ -340,6 +343,8 @@ def detect_kicad():


def parse_defines(args):
if args.defs_from_env:
GS.cli_defines.update(os.environ)
for define in args.define:
if '=' not in define:
GS.exit_with_error(f'Malformed `define` option, must be VARIABLE=VALUE ({define})', EXIT_BAD_ARGS)
Expand Down

0 comments on commit 7c7d3af

Please sign in to comment.