-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add support for setting ZMK version #53
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fdfff8a
feat: Add "zmk version" command
joelspadin 196a9f2
feat(init): Add options for URL, directory, and ZMK version
joelspadin 8603770
fix(yaml): Better preserve YAML formatting
joelspadin bec7c23
fix: Update ZMK version more thoroughly
joelspadin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """ | ||
| "zmk version" command. | ||
| """ | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| import rich | ||
| import typer | ||
| from rich.table import Table | ||
|
|
||
| from ..config import get_config | ||
| from ..exceptions import FatalError | ||
| from ..remote import Remote | ||
| from ..repo import Repo | ||
|
|
||
|
|
||
| def version( | ||
| ctx: typer.Context, | ||
| revision: Annotated[ | ||
| str | None, | ||
| typer.Argument( | ||
| help="Switch to this ZMK version. Prints the current ZMK version if omitted.", | ||
| ), | ||
| ] = None, | ||
| list_versions: Annotated[ | ||
| bool | None, | ||
| typer.Option("--list", "-l", help="Print the available versions and exit."), | ||
| ] = False, | ||
| ) -> None: | ||
| """Get or set the ZMK version.""" | ||
|
|
||
| cfg = get_config(ctx) | ||
| repo = cfg.get_repo() | ||
|
|
||
| if list_versions: | ||
| _print_versions(repo) | ||
| elif revision is None: | ||
| _print_current_version(repo) | ||
| else: | ||
| _set_version(repo, revision) | ||
|
|
||
|
|
||
| def _print_versions(repo: Repo): | ||
| zmk = repo.get_west_zmk_project() | ||
| remote = Remote(zmk.url) | ||
|
|
||
| if not remote.repo_exists(): | ||
| raise FatalError(f"Invalid repository URL: {zmk.url}") | ||
|
|
||
| tags = remote.get_tags() | ||
|
|
||
| if not tags: | ||
| raise FatalError(f"{zmk.url} does not have any tagged commits.") | ||
|
|
||
| for tag in tags: | ||
| print(tag) | ||
|
|
||
|
|
||
| def _print_current_version(repo: Repo): | ||
| zmk = repo.get_west_zmk_project() | ||
|
|
||
| grid = Table.grid() | ||
| grid.add_column() | ||
| grid.add_column() | ||
| grid.add_row("[bright_blue]Remote: [/bright_blue]", zmk.url) | ||
| grid.add_row("[bright_blue]Revision: [/bright_blue]", zmk.revision) | ||
|
|
||
| rich.print(grid) | ||
|
|
||
|
|
||
| def _set_version(repo: Repo, revision: str): | ||
| repo.set_zmk_version(revision) | ||
| repo.run_west("update") | ||
|
|
||
| rich.print() | ||
| rich.print(f'ZMK is now using revision "{revision}"') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth making one of these an Option, e.g. to be able to specify the name without the url. I'd vote for url to be an option and name to stay an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following https://git-scm.com/docs/git-clone for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess using the interactive mode asks for both separately, so it isn't very important either way.