13 Commits

Author SHA1 Message Date
Sigurd Spieckermann
ba514b424f fix: parse CLI data using question's answer parser 2023-02-27 18:48:58 +01:00
Sigurd Spieckermann
c9e9c100ec fix(cli): use --conflict flag only in copier update subcommand 2023-02-21 21:21:01 +00:00
Nils de Bruin
2d4c472e8a
feat: let answers file exist in a subdirectory
See discussion: https://github.com/copier-org/copier/discussions/859

Co-authored-by: Jairo Llopis <yajo.sk8@gmail.com>
2023-02-20 20:56:45 +00:00
Thierry Gaugry
468b9ff78c
fix: --skip option was ignored (#966)
* Fix missing skip_if_exists param

* Add tests for skip cli flag

---------

Co-authored-by: Thierry Gaugry <thierry.gaugry@ariadnext.com>
2023-02-17 19:38:50 +00:00
Timothée Mazzucotelli
534a888a0a
feat: Add __main__ module allowing to run python -m copier (#384)
* feat: Add `__main__` module allowing to run `python -m copier`

* tests: Add test for `python -m copier`
2021-04-06 08:46:06 +01:00
Jairo Llopis
1482de4972
wip 2021-03-05 17:33:11 +00:00
Jairo Llopis
cda93273c1
Enhanced user input (#260)
* use a new toolkit for user prompting: questionary (patched).
* multiline questions.
* conditional questions.
* new toolkit for ui tests: pexpect.
* fix lots of tests.
* fix windows builds with newer poetry-dynamic-versioning.
* linters and mypy are now tests, to have faster ci.
* update deprecated ci commands.
* removed dependencies from old times.
* Remove toml 0.5+ syntax (dotted keys)
* Use powershell where syntax is compatible
* Change skip to xfail
* xfail pexpect tests on windows. I'm tired of trying to make it work
* more docs
* possibly something more.
2020-10-12 08:56:46 +01:00
Jairo Llopis
823f3a1935 Remove dst fixture
This is redundant with pytest's native `tmp_path` fixture, so we use that one instead now.
2020-06-23 07:58:03 +00:00
Jairo Llopis
58210e6ed6
Fix --answers-file
This is a switch attribute, not a flag.

Without this patch, using this feature yields this error:

```
➤ copier -fa .altered-copier-answers.yml update
Traceback (most recent call last):
  File "/home/yajo/.local/bin/copier", line 8, in <module>
    sys.exit(CopierApp.run())
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/plumbum/cli/application.py", line 577, in run
    inst, retcode = subapp.run(argv, exit=False)
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/plumbum/cli/application.py", line 572, in run
    retcode = inst.main(*tailargs)
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/cli.py", line 17, in _wrapper
    return method(*args, **kwargs)
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/cli.py", line 172, in main
    dst_path=destination_path, only_diff=self.only_diff,
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/cli.py", line 111, in _copy
    **kwargs,
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/main.py", line 123, in copy
    conf = make_config(**locals())
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/config/factory.py", line 59, in make_config
    answers_data.update(load_answersfile_data(dst_path, answers_file))
  File "/home/yajo/.local/pipx/venvs/copier/lib64/python3.7/site-packages/copier/config/user_data.py", line 90, in load_answersfile_data
    with open(Path(dst_path) / (answers_file or ".copier-answers.yml")) as fd:
  File "/usr/lib64/python3.7/pathlib.py", line 920, in __truediv__
    return self._make_child((key,))
  File "/usr/lib64/python3.7/pathlib.py", line 699, in _make_child
    drv, root, parts = self._parse_args(args)
  File "/usr/lib64/python3.7/pathlib.py", line 653, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not bool
```

@Tecnativa TT20357
2020-03-25 10:34:58 +00:00
Jairo Llopis
1d8a2a47c3
Fix copier --help
A bug introduced in #121 made copier --help stop working.

Test added.
2020-02-24 11:24:00 +00:00
Jairo Llopis
5b48f352a4 Fix new checks
- Add ignore comment on `BaseModel` instances that are correctly following what `pydantic` wants, to let flake8-bugbear be happy.
- Remove unused import.
2019-12-10 11:52:05 +00:00
Jairo Llopis
899f5d6a66
Basic support for automatic copy updates
This is a totally breaking PR. It had to come sooner or later...

Before this patch, copier had some ugly problems:

- If a file was called `--exclude`, you couldn't add it to `--extra-paths` due to using `nargs='*'` in an option. It is a weird thing that `ArgumentParser` allows to do, but can potentially lead to unfixable problems.
- Argument parsing was a little bit handycraft work.

Meet [Plumbum](https://plumbum.readthedocs.io/), the swiss army knife for CLI packages:

- CLI has been refactored as a plumbum application.
- Tests for CLI parsing removed, since they were incompatible and we are using a well-tested CLI parsing library now after all.
- The application now includes 2 subcommands: `copy` and `update`.
- If called without args, or with 1, it will use `update`.
- If called with 2 args, it will use `copy` (this preserves old usage unchanged, unless you are copying from a template called `copy` or `update`; in such corner case, just call it as `copier copy copy destination` instead).
- `copier --help` and `copier --help-all` are more useful now.

And you might be wondering... Adding such a big dependency just for that? Well, actually plumbum supports more than just CLI applications: supports sane execution of local & remote commands, sane output coloring, sane user prompting... Possibly it will make Copier go to the next level as we keep on using it more. Just take a look at its docs! You'll love it 😉

Of course, all that new CLI had to be reflected in API changes:

- `src_path` is now optional (`None` by default). In such case, copier will try to guess the `src_path` from the `.copier-answers.yml` file in the copy, or fail otherwise.
- `dst_path` is also now optional (`.` by default), meaning that without a `src_path`, you'll be trying to copy anything else to current `$PWD`.
- The builtin `_log` variable, which contains all necessary data for copy updates, now has also a `_src_path` key that points to the original source. This only happens when it was copied from a git repo or from an absolute path in the local disk, as relative paths are not easily reproducible in next updates (they depend on the user's CWD when running copier).
- A new `original_src_path` variable goes around, indicating the git repo or abs system path passed to `src_path` on the initial call. This is just to be stored in `_log` as explained.

```bash
copier gh:example/template destination
cd destination
echo my changes >> anywhere
git commit -m changing .
copier # Equals to `copier update .`
git commit -m 'copier update' .
```

🎉 You're updated!

This is an importan step to complete #88.

@Tecnativa TT20357
2019-12-05 13:51:55 +00:00
Ben Felder
79a1d04020 Refactored parse_args for better testability.
Added test_cli.py.

Removed unused dynamic import from cli.py.

Added tests for cli flags.

Added test for cli.run.

Improved test_good_cli_run.

Refactored parser generation for better testability.

test_cli_args replacing test_cli_flags.

Parametrized test_invalid_cli_args.

Added test_make_parser_bad_config.
2019-09-22 20:47:36 +02:00