Skip to content

Commit

Permalink
Add some properties clients are using to MILCInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
skullydazed committed Feb 5, 2024
1 parent ec54115 commit 88b6835
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion milc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Any, Optional

from .emoji import EMOJI_LOGLEVELS
from .milc import MILC
from .milc_interface import MILCInterface

if 'MILC_IGNORE_DEPRECATED' not in os.environ:
Expand All @@ -37,7 +38,7 @@ def set_metadata(
author: Optional[str] = None,
version: Optional[str] = None,
logger: Optional[logging.Logger] = None,
) -> Any:
) -> MILCInterface:
"""Set metadata about your program.
Deprecated: Use `cli.milc_options()` instead.
Expand Down
8 changes: 8 additions & 0 deletions milc/milc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def description(self) -> Optional[str]:
def description(self, value: str) -> None:
self._arg_parser.description = value

@property
def subcommand_name(self) -> Optional[str]:
if self._subcommand is not None:
name: str = self._subcommand.__name__
return name

return None

def argv_name(self) -> str:
"""Returns the name of our program by examining argv.
"""
Expand Down
19 changes: 19 additions & 0 deletions milc/milc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is where the public interface for `cli` is kept. This allows us to reinstantiate MILC without having to recreate the cli object, as well as allowing us to have a well defined public API.
"""
import warnings
import sys
from logging import Logger
from pathlib import Path
Expand Down Expand Up @@ -68,6 +69,24 @@ def interactive(self) -> bool:
def log(self) -> Logger:
return self.milc.log

@property
def platform(self) -> str:
return self.milc.platform

@property
def _subcommand(self) -> Any:
warnings.warn("cli._subcommand has been deprecated, please use cli.subcommand_name to get the subcommand name instead.", stacklevel=2)

return self.milc._subcommand

@property
def subcommands(self) -> Dict[str, Any]:
return self.milc.subcommands

@property
def subcommand_name(self) -> Any:
return self.milc._subcommand

def echo(self, text: str, *args: Any, **kwargs: Any) -> None:
"""Print colorized text to stdout.
Expand Down

0 comments on commit 88b6835

Please sign in to comment.