Run
The main access, start here.
Wrap your configuration dataclass into run
to access the interface. An interface is chosen automatically,
with the preference of the graphical one, regressed to a text interface for machines without display.
Besides, if given a configuration dataclass, the function enriches it with the CLI commands and possibly
with the default from a config file if such exists.
It searches the config file in the current working directory,
with the program name ending on .yaml, ex: program.py
will fetch ./program.yaml
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env_or_list |
Type[EnvClass] | list[Type[Command]] | None
|
|
None
|
ask_on_empty_cli |
bool
|
If program was launched with no arguments (empty CLI), invokes self.form() to edit the fields.
(Withdrawn when |
False
|
title |
str
|
The main title. If not set, taken from |
''
|
config_file |
Path | str | bool
|
File to load YAML to be merged with the configuration.
You do not have to re-define all the settings in the config file, you can choose a few.
If set to True (default), we try to find one in the current working dir,
whose name stem is the same as the program's.
Ex: |
True
|
add_verbosity |
bool
|
Adds the verbose flag that automatically sets the level to |
True
|
ask_for_missing |
bool
|
True
|
|
interface |
Type[Mininterface] | Literal['gui'] | Literal['tui']
|
Which interface to prefer. By default, we use the GUI, the fallback is the TUI. You may write "gui" or "tui" literal or pass a specific Mininterface type, see the full list of possible interfaces. |
None
|
args |
Optional[Sequence[str]]
|
Parse arguments from a sequence instead of the command line. |
None
|
Kwargs: The same as for argparse.ArgumentParser.
Returns:
Type | Description |
---|---|
Mininterface[EnvClass]
|
An interface, ready to be used. |
You cay context manager the function by a with
statement.
The stdout will be redirected to the interface (ex. a GUI window).
from dataclasses import dataclass
from mininterface import run
@dataclass
class Env:
my_number: int = 4
with run(Env) as m:
print(f"Your important number is {m.env.my_number}")
boolean = m.is_yes("Is that alright?")