Skip to content

Commit

Permalink
feat: Skipping hide_input flag options
Browse files Browse the repository at this point in the history
  • Loading branch information
Aradhya-Tripathi committed Jun 14, 2023
1 parent bcacb3c commit 84d34b4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
8 changes: 2 additions & 6 deletions trogon/run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ArgumentSchema,
MultiValueParamData,
)
from trogon.widgets.parameter_controls import ValueNotSupplied, HiddenValueInput
from trogon.widgets.parameter_controls import ValueNotSupplied


@dataclass
Expand Down Expand Up @@ -231,11 +231,7 @@ def to_cli_string(self, include_root_command: bool = False) -> Text:
text_renderables = []
for arg in args:
text_renderables.append(
Text(
str(arg.display)
if isinstance(arg, HiddenValueInput)
else shlex.quote(str(arg))
)
Text(shlex.quote(str(arg)))
if arg != ValueNotSupplied()
else Text("???", style="bold black on red")
)
Expand Down
8 changes: 2 additions & 6 deletions trogon/trogon.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from trogon.widgets.command_tree import CommandTree
from trogon.widgets.form import CommandForm
from trogon.widgets.multiple_choice import NonFocusableVerticalScroll
from trogon.widgets.parameter_controls import HiddenValueInput

try:
from importlib import metadata # type: ignore
Expand Down Expand Up @@ -252,12 +251,9 @@ def run(
console = Console()
if self.post_run_command and self.execute_on_exit:
console.print(
f"Running [b cyan]{self.app_name} {' '.join(s.display if isinstance(s, HiddenValueInput) else shlex.quote(s) for s in self.post_run_command)}[/]"
f"Running [b cyan]{self.app_name} {' '.join(shlex.quote(s) for s in self.post_run_command)}[/]"
)
self.post_run_command = [
cmd.value if isinstance(cmd, HiddenValueInput) else cmd
for cmd in self.post_run_command
]

split_app_name = shlex.split(self.app_name)
program_name = shlex.split(self.app_name)[0]
arguments = [*split_app_name, *self.post_run_command]
Expand Down
5 changes: 5 additions & 0 deletions trogon/widgets/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def compose(self) -> ComposeResult:
if options:
yield Label(f"Options", classes="command-form-heading")
for option in options:
if option.hide_input:
continue

controls = ParameterControls(option, id=option.key)
if self.first_control is None:
self.first_control = controls
Expand Down Expand Up @@ -172,6 +175,8 @@ def _form_changed(self) -> None:
# For each of the options in the schema for this command,
# lets grab the values the user has supplied for them in the form.
for option in command.options:
if option.hide_input:
continue
parameter_control = self.query_one(f"#{option.key}", ParameterControls)
value = parameter_control.get_values()
for v in value.values:
Expand Down
20 changes: 1 addition & 19 deletions trogon/widgets/parameter_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ def __bool__(self):
return False


class HiddenValueInput:
def __init__(self, value: str) -> None:
self.value = value
self.display = len(value) * "*"


class ParameterControls(Widget):
def __init__(
self,
Expand Down Expand Up @@ -120,7 +114,6 @@ def compose(self) -> ComposeResult:
multiple = schema.multiple
is_option = isinstance(schema, OptionSchema)
hidden = getattr(schema, "hidden", False)
hide_input = getattr(schema, "hide_input", False)
nargs = schema.nargs

label = self._make_command_form_control_label(
Expand Down Expand Up @@ -150,7 +143,6 @@ def compose(self) -> ComposeResult:
multiple_choice_widget = control_method(
default=default,
label=label,
hide_input=hide_input,
multiple=multiple,
schema=schema,
control_id=schema.key,
Expand Down Expand Up @@ -217,7 +209,6 @@ def make_widget_group(self) -> Iterable[Widget]:
required = schema.required
is_option = isinstance(schema, OptionSchema)
hidden = getattr(schema, "hidden", False)
hide_input = getattr(schema, "hide_input", False)
label = self._make_command_form_control_label(
name=name,
type=parameter_type,
Expand All @@ -242,7 +233,6 @@ def make_widget_group(self) -> Iterable[Widget]:
default=default,
label=label,
multiple=multiple,
hide_input=hide_input,
schema=schema,
control_id=schema.key,
)
Expand Down Expand Up @@ -280,8 +270,6 @@ def _get_form_control_value(control: ControlWidgetType) -> Any:
return ValueNotSupplied()
return control.value
elif isinstance(control, Input):
if control.password and control.value != "":
return HiddenValueInput(control.value)
return (
ValueNotSupplied() if control.value == "" else control.value
) # TODO: We should only return "" when user selects a checkbox - needs custom widget.
Expand Down Expand Up @@ -365,13 +353,9 @@ def make_text_control(
label: Text | None,
multiple: bool,
schema: OptionSchema | ArgumentSchema,
hide_input: bool,
control_id: str,
) -> Widget:
control = Input(
classes=f"command-form-input {control_id}",
password=hide_input,
)
control = Input(classes=f"command-form-input {control_id}")
yield control
return control

Expand All @@ -381,7 +365,6 @@ def make_checkbox_control(
label: Text | None,
multiple: bool,
schema: OptionSchema | ArgumentSchema,
hide_input: bool,
control_id: str,
) -> Widget:
if default.values:
Expand All @@ -404,7 +387,6 @@ def make_choice_control(
label: Text | None,
multiple: bool,
schema: OptionSchema | ArgumentSchema,
hide_input: bool,
control_id: str,
choices: list[str],
) -> Widget:
Expand Down

0 comments on commit 84d34b4

Please sign in to comment.