Skip to content

Commit

Permalink
Update :config to look more like :settings (#1101)
Browse files Browse the repository at this point in the history
* Update to look like settings

* Changelog

* Formatting

* Test fix

* Formatting

Co-authored-by: Ganesh Nalawade <ganesh634@gmail.com>
  • Loading branch information
cidrblock and ganeshrn authored Mar 18, 2022
1 parent 605587a commit f16f66b
Show file tree
Hide file tree
Showing 50 changed files with 1,042 additions and 1,032 deletions.
3 changes: 3 additions & 0 deletions docs/changelog-fragments.d/1101.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Updated the formatting of `:config` to align with `:settings` in the UI.

-- by {user}`cidrblock`
31 changes: 21 additions & 10 deletions src/ansible_navigator/actions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def color_menu(colno: int, colname: str, entry: Dict[str, Any]) -> Tuple[int, in
:param entry: The menu entry
:returns: The color and decoration
"""
if entry["__default"] is False:
if entry["default"] is False:
return 3, 0
return 2, 0

Expand All @@ -52,12 +52,12 @@ def content_heading(obj: Any, screen_w: int) -> Optional[CursesLines]:
:param screen_w: The current screen width
:returns: The heading
"""
string = obj["option"].replace("_", " ")
if obj["__default"] is False:
string += f" (current: {obj['__current_value']}) (default: {obj['default']})"
string = obj["name"]
if obj["default"] is False:
string += f" (current: {obj['current_value']}) (default: {obj['default_value']})"
color = 3
else:
string += f" (current/default: {obj['__current_value']})"
string += f" (current/default: {obj['current_value']})"
color = 2

string = string + (" " * (screen_w - len(string) + 1))
Expand Down Expand Up @@ -190,7 +190,7 @@ def _build_main_menu(self):
"""
return Step(
name="all_options",
columns=["option", "__default", "source", "via", "__current_value"],
columns=["name", "default", "source", "__current"],
select_func=self._build_option_content,
step_type="menu",
value=self._config,
Expand Down Expand Up @@ -308,6 +308,8 @@ def _parse_and_merge(self, list_output, dump_output) -> None:
:param dump_output: The output from config dump
:returns: Nothing
"""
# pylint: disable=too-many-branches
# pylint: disable=too-many-locals
try:
parsed = yaml.load(list_output, Loader=Loader)
self._logger.debug("yaml loading list output succeeded")
Expand Down Expand Up @@ -335,8 +337,15 @@ def _parse_and_merge(self, list_output, dump_output) -> None:
else:
parsed[variable]["source"] = source
parsed[variable]["via"] = source
parsed[variable]["current"] = current
parsed[variable]["__current_value"] = extracted.groupdict()["current"]
current_as_str = str(current)

target_screen_w = int(100 / 2) # half a wide screen
if len(current_as_str) > target_screen_w:
more_indicator = "..."
text_width = target_screen_w - len(more_indicator)
current_as_str = f"{current_as_str[0:text_width]}{more_indicator}"
parsed[variable]["__current"] = current_as_str
parsed[variable]["current_value"] = current
except KeyError:
self._logger.error("variable '%s' not found in list output")
return None
Expand All @@ -346,10 +355,12 @@ def _parse_and_merge(self, list_output, dump_output) -> None:

for key, value in parsed.items():
value["option"] = key
value["name"] = key.replace("_", " ").capitalize()
value["default_value"] = value.get("default", "None")
if value["source"] == "default":
value["__default"] = True
value["default"] = True
else:
value["__default"] = False
value["default"] = False

self._config = list(parsed.values())
self._logger.debug("parsed and merged list and dump successfully")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
"compared_fixture": true
},
"output": [
" OPTION DEFAULT SOURCE VIA CURRENT VALUE",
" 0│ACTION_WARNINGS True default default True",
" 1│AGNOSTIC_BECOME_PROMPT True default default True",
" 2│ALLOW_WORLD_READABLE_TMPFILES True default default False",
" 3│ANSIBLE_CONNECTION_PATH True default default None",
" 4│ANSIBLE_COW_ACCEPTLIST True default default ['bud-frogs', 'bunny', 'cheese', 'daemon', 'default', 'dragon', 'elephant-in-snake', 'elephant', 'eyes', 'hellokitty', 'kitty', 'luke-koala', 'meow', 'milk', 'moofasa', 'moose', 'ren', 'sheep', 'small', 'ste",
" 5│ANSIBLE_COW_PATH True default default None",
" 6│ANSIBLE_COW_SELECTION True default default default",
" 7│ANSIBLE_FORCE_COLOR True default default False",
" 8│ANSIBLE_NOCOLOR True default default False",
" 9│ANSIBLE_NOCOWS True default default False",
" 10│ANSIBLE_PIPELINING True default default False",
" 11│ANY_ERRORS_FATAL True default default False",
" 12│BECOME_ALLOW_SAME_USER True default default False",
" 13│BECOME_PLUGIN_PATH True default default XXXXXXXXXXXXX",
" 14│CACHE_PLUGIN False env ANSIBLE_CACHE_PLUGIN jsonfile",
" 15│CACHE_PLUGIN_CONNECTION False env ANSIBLE_CACHE_PLUGIN_CONNECTION XXXXXXXXXXXXX",
" 16│CACHE_PLUGIN_PREFIX True default default ansible_facts",
" 17│CACHE_PLUGIN_TIMEOUT False env ANSIBLE_CACHE_PLUGIN_TIMEOUT 42",
" 18│CALLABLE_ACCEPT_LIST True default default []",
" 19│CALLBACKS_ENABLED True default default []",
" 20│COLLECTIONS_ON_ANSIBLE_VERSION_MISMATCH True default default warning",
" 21│COLLECTIONS_PATHS True default default XXXXXXXXXXXXX",
" 22│COLLECTIONS_SCAN_SYS_PATH True default default True",
" NAME DEFAULT SOURCE CURRENT",
" 0│Action warnings True default True",
" 1│Agnostic become prompt True default True",
" 2│Allow world readable tmpfiles True default False",
" 3│Ansible connection path True default None",
" 4│Ansible cow acceptlist True default ['bud-frogs', 'bunny', 'cheese', 'daemon', 'def...",
" 5│Ansible cow path True default None",
" 6│Ansible cow selection True default default",
" 7│Ansible force color True default False",
" 8│Ansible nocolor True default False",
" 9│Ansible nocows True default False",
" 10│Ansible pipelining True default False",
" 11│Any errors fatal True default False",
" 12│Become allow same user True default False",
" 13│Become plugin path True default XXXXXXX",
" 14│Cache plugin False env jsonfile",
" 15│Cache plugin connection False env XXXXXXX",
" 16│Cache plugin prefix True default ansible_facts",
" 17│Cache plugin timeout False env 42",
" 18│Callable accept list True default []",
" 19│Callbacks enabled True default []",
" 20│Collections on ansible version mismatch True default warning",
" 21│Collections paths True default XXXXXXX",
" 22│Collections scan sys path True default True",
"^f/PgUp page up ^b/PgDn page down ↑↓ scroll esc back [0-9] goto :help help"
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "test[1-:f CACHE_PLUGIN_TIMEOUT-filter for cache plugin timeout]",
"name": "test[1-:f Cache plugin timeout-filter for cache plugin timeout]",
"index": 1,
"comment": "filter for cache plugin timeout",
"additional_information": {
Expand All @@ -8,8 +8,8 @@
"compared_fixture": true
},
"output": [
" OPTION DEFAULT SOURCE VIA CURRENT VALUE",
"0│CACHE_PLUGIN_TIMEOUT False env ANSIBLE_CACHE_PLUGIN_TIMEOUT 42",
" NAME DEFAULT SOURCE CURRENT",
"0│Cache plugin timeout False env 42",
"^f/PgUp page up ^b/PgDn page down ↑↓ scroll esc back [0-9] goto :help help"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
"compared_fixture": true
},
"output": [
"CACHE PLUGIN TIMEOUT (current: 42) (default: 86400)",
"Cache plugin timeout (current: 42) (default: 86400)",
" 0│---",
" 1│current: 42",
" 2│default: 86400",
" 3│description: Expiration timeout for the cache plugin data",
" 4│env:",
" 5│- name: ANSIBLE_CACHE_PLUGIN_TIMEOUT",
" 6│ini:",
" 7│- key: fact_caching_timeout",
" 8│ section: defaults",
" 9│name: Cache Plugin expiration timeout",
"10│option: CACHE_PLUGIN_TIMEOUT",
"11│source: env",
"12│type: integer",
"13│via: ANSIBLE_CACHE_PLUGIN_TIMEOUT",
"14│yaml:",
"15│ key: facts.cache.timeout",
" 1│current_value: 42",
" 2│default: false",
" 3│default_value: 86400",
" 4│description: Expiration timeout for the cache plugin data",
" 5│env:",
" 6│- name: ANSIBLE_CACHE_PLUGIN_TIMEOUT",
" 7│ini:",
" 8│- key: fact_caching_timeout",
" 9│ section: defaults",
"10│name: Cache plugin timeout",
"11│option: CACHE_PLUGIN_TIMEOUT",
"12│source: env",
"13│type: integer",
"14│via: ANSIBLE_CACHE_PLUGIN_TIMEOUT",
"15│yaml:",
"16│ key: facts.cache.timeout",
"^f/PgUp page up ^b/PgDn page down ↑↓ scroll esc back - previous + next [0-9] goto :help help"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"compared_fixture": true
},
"output": [
" OPTION DEFAULT SOURCE VIA CURRENT VALUE",
"0│CACHE_PLUGIN_TIMEOUT False env ANSIBLE_CACHE_PLUGIN_TIMEOUT 42",
" NAME DEFAULT SOURCE CURRENT",
"0│Cache plugin timeout False env 42",
"^f/PgUp page up ^b/PgDn page down ↑↓ scroll esc back [0-9] goto :help help"
]
}
Loading

0 comments on commit f16f66b

Please sign in to comment.