-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added quiet output mode option for CLI change command. Added verbose …
…and json output mode options for CLI view command.
- Loading branch information
1 parent
8f2f9fe
commit 157db3b
Showing
8 changed files
with
210 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -19,4 +19,4 @@ keywords: | |
- pyproject.toml | ||
- CITATION.cff | ||
license: Apache-2.0 | ||
version: "3.1.1" | ||
version: "3.1.2" |
This file contains 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 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 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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
from typing_extensions import Annotated | ||
import typer | ||
from cff2toml.cli.about_command.about_command import app_about | ||
from cff2toml.cli.about_command.about_command import about_command | ||
from cff2toml.cli.change_command.change_command import app_change | ||
from cff2toml.cli.context_helpers import TyperContextDictionary | ||
from cff2toml.cli.view_command.view_command import app_view | ||
|
||
app = typer.Typer(no_args_is_help=True) | ||
|
||
app.add_typer(app_about, name="about", | ||
help="View information about cff2toml.") | ||
|
||
# if you ever want to add a parameter that works without having to invoke a command | ||
# then you need to use the 'invoke_without_command=True' argument for the callback decorator | ||
# https://typer.tiangolo.com/tutorial/commands/context/ | ||
|
||
@app.callback() | ||
def main(ctx: typer.Context, quiet: Annotated[bool, typer.Option(help="Hidden output mode (Only for 'change' command)")] = False, verbose: Annotated[bool, typer.Option(help="Verbose output mode")] = False, json: Annotated[bool, typer.Option(help="JSON output mode")] = False): | ||
d = TyperContextDictionary(ctx=ctx) | ||
d.set('quiet', quiet) | ||
d.set('verbose', verbose) | ||
d.set('json', json) | ||
|
||
|
||
@app.command(name="about", help="View information about cff2toml.") | ||
def about(ctx: typer.Context): | ||
about_command(ctx=ctx) | ||
|
||
|
||
app.add_typer(app_change, name="change", | ||
help="Change metadata for both CITATION.cff and pyproject.toml files.") | ||
help="Change metadata to specific value for both CITATION.cff and pyproject.toml files.") | ||
|
||
app.add_typer(app_view, name="view", | ||
help="View metadata for both CITATION.cff and pyproject.toml files.") |
This file contains 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 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,36 @@ | ||
from typing import Any | ||
|
||
from pydantic import BaseModel | ||
from cff2toml.models.files.cff_file import CffFile | ||
from cff2toml.models.files.pyproject_toml_file import PyprojectTomlFile | ||
from cff2toml.models.files.synchronizers.cff_and_pyproject_toml_file_synchronizer import PROPERTY_MAPPINGS | ||
|
||
|
||
class CommandMetadataOutput(BaseModel): | ||
command: str | ||
cff_file_path: str | ||
pyproject_toml_file_path: str | ||
common_metadata_name: str | ||
cff_file_metadata_name: str = '' | ||
cff_file_metadata_value_before_command: Any = '' | ||
cff_file_metadata_value_after_command: Any = '' | ||
pyproject_toml_file_metadata_name: str = '' | ||
pyproject_toml_file_metadata_value_before_command: Any = '' | ||
pyproject_toml_file_metadata_value_after_command: Any = '' | ||
|
||
def setup(self): | ||
cff_file = CffFile(file_path=self.cff_file_path) | ||
pyproject_toml_file = PyprojectTomlFile( | ||
file_path=self.pyproject_toml_file_path) | ||
self.pyproject_toml_file_metadata_name = PROPERTY_MAPPINGS[self.common_metadata_name][0] | ||
self.cff_file_metadata_name = PROPERTY_MAPPINGS[self.common_metadata_name][1] | ||
self.cff_file_metadata_value_before_command = cff_file.get_metadata( | ||
self.cff_file_metadata_name, '') | ||
self.pyproject_toml_file_metadata_value_before_command = pyproject_toml_file.get_metadata( | ||
self.pyproject_toml_file_metadata_name) | ||
self.cff_file_metadata_value_after_command = self.cff_file_metadata_value_before_command | ||
self.pyproject_toml_file_metadata_value_after_command = self.pyproject_toml_file_metadata_value_before_command | ||
|
||
def set_after_value(self, value: Any) -> None: | ||
self.cff_file_metadata_value_after_command = value | ||
self.pyproject_toml_file_metadata_value_after_command = value |
This file contains 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,39 @@ | ||
from typing import Any | ||
import typer | ||
|
||
|
||
class TyperContextDictionary: | ||
|
||
_d: dict | ||
|
||
def __init__(self, ctx: typer.Context): | ||
if not isinstance(ctx.obj, dict): | ||
ctx.obj = dict() | ||
self._d = ctx.obj | ||
|
||
def has(self, key: str) -> bool: | ||
return key in self._d | ||
|
||
def get(self, key: str, default_value: Any = None): | ||
if key in self._d: | ||
return self._d[key] | ||
else: | ||
return default_value | ||
|
||
def set(self, key: str, value: Any): | ||
self._d[key] = value | ||
|
||
|
||
def is_quiet_output(ctx: typer.Context): | ||
d = TyperContextDictionary(ctx=ctx) | ||
return d.get(key='quiet', default_value=False) | ||
|
||
|
||
def is_verbose_output(ctx: typer.Context): | ||
d = TyperContextDictionary(ctx=ctx) | ||
return d.get(key='verbose', default_value=False) | ||
|
||
|
||
def is_json_output(ctx: typer.Context): | ||
d = TyperContextDictionary(ctx=ctx) | ||
return d.get(key='json', default_value=False) |
Oops, something went wrong.