Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve update command #159

Merged
merged 7 commits into from Dec 28, 2022
Merged

Conversation

gmsantos
Copy link
Contributor

This PR tries to improve how the update command works in cases where the cookiecutter template receives new variable values.

It handles two scenarios:

  • When you want to update an input value by using the --cookiecutter-input flag
  • When you want your project to be updated based on updates in private variables from the cookiecutter template with a new --refresh-private-variables flag (feel free to suggest some better naming 😄 )

To test those changes, I created a fork of the https://github.com/cruft/cookiecutter-test repo and used those two branches:

https://github.com/gmsantos/cookiecutter-test/tree/input
https://github.com/gmsantos/cookiecutter-test/tree/input-updated

Those branches can be added back in a similar way as cruft/cookiecutter-test#1 (I can sync the tests after that).

@codecov
Copy link

codecov bot commented May 28, 2022

Codecov Report

Base: 99.77% // Head: 99.78% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (02c4075) compared to base (4a471ad).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #159   +/-   ##
=======================================
  Coverage   99.77%   99.78%           
=======================================
  Files          21       21           
  Lines         899      934   +35     
=======================================
+ Hits          897      932   +35     
  Misses          2        2           
Impacted Files Coverage Δ
cruft/_cli.py 100.00% <ø> (ø)
cruft/_commands/update.py 98.24% <100.00%> (+0.09%) ⬆️
tests/test_cli.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gmsantos
Copy link
Contributor Author

gmsantos commented Jun 7, 2022

@samj1912 let me know when you have some time to review this one :)

@simu
Copy link
Contributor

simu commented Jul 7, 2022

I was planning to submit a similar PR (see my proposal in #57 (comment)), good to see we're not the only ones looking for a more versatile update command.

simu added a commit to projectsyn/cruft that referenced this pull request Jul 7, 2022
This commit adds support for providing cookiecutter arguments on the
command line for `cruft update`. If any arguments are provided on the
command line `cruft update` will always render the template regardless
of whether the user has requested to update to a new template version or
not.

Ideally this change will be applied after
cruft#159 as it's been developed on top
of that PR originally.
simu added a commit to projectsyn/cruft that referenced this pull request Jul 14, 2022
This commit adds support for providing cookiecutter arguments on the
command line for `cruft update`. If any arguments are provided on the
command line `cruft update` will always render the template regardless
of whether the user has requested to update to a new template version or
not.

Ideally this change will be applied after
cruft#159 as it's been developed on top
of that PR originally.
simu added a commit to projectsyn/cruft that referenced this pull request Jul 14, 2022
This commit adds support for providing cookiecutter arguments on the
command line for `cruft update`. If any arguments are provided on the
command line `cruft update` will always render the template regardless
of whether the user has requested to update to a new template version or
not.

Ideally this change will be applied after
cruft#159 as it's been developed on top
of that PR originally.
simu added a commit to projectsyn/commodore that referenced this pull request Jul 14, 2022
@lsorber
Copy link

lsorber commented Jul 25, 2022

With Cookiecutter 2.2.0's support for boolean variables, perhaps this PR could also be extended to support transitioning from string values such as "0" or "1" to the boolean values false and true automatically (when the Cookiecutter template uses boolean values)?

Specifically, the documentation on boolean variables says that these values should map to True and False, respectively:

  1. True values: “1”, “true”, “t”, “yes”, “y”, “on”
  2. False values: “0”, “false”, “f”, “no”, “n”, “off”

@gmsantos
Copy link
Contributor Author

@lsorber not sure if is related to these changes. Better do it in a separate PR.

If the user asks to re-input the cookiecutter context, it might try to
update some value. In that case, it is intersting to skip the
early return of the same template commit revision.
If we reuse the same inputs for both current and new context
cruft will not be able to capture inputs changes, resulting in
less changes than the expected.
At this moment, it is not possible to update a cookiecutter private
variable with the update command because the current context
are not aware of the template changes.

Removing the private variables from cruft_state before creating
the updated context seems to refresh the private variables from
the template.
@stefan-caraiman
Copy link

bump, any updates on this feature?

@timothycrosley timothycrosley merged commit 3695933 into cruft:master Dec 28, 2022
@gmsantos gmsantos deleted the improve-update-command branch January 9, 2023 04:04
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.

None yet

6 participants