Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Initial groundwork for wizard improvements #5728

Merged
merged 7 commits into from Nov 18, 2020

Conversation

kyleknap
Copy link
Member

This pull request adds the initial groundwork for wizard improvements. This change allows the prompts to be displayed as a basic form-based UI that you can type input into. To test it, I updated the cli-dev wizard-dev to start using this new scaffolding. So you can try it out by inputting:

aws cli-dev wizard-dev --run-wizard file://path/to/wizard.yml

I tried to break this as best as I could into separate commits to accurately represent what changes I made but to summarize:

  • Added a new ui package to host anything related to prompt toolkit UI.
  • Added a new wizard app that uses the UI components to make a basic form-based wizard UI
  • Updated the cli-dev wizard-dev command to use this UI
  • Generalized the prompt toolkit application stubber to use for wizards
  • Added basic behavior tests for the wizard application as a starting point for adding future tests. (I still want to add more once the UI starts becoming finalized)
  • Updated the auto-prompt tests to use the updated prompt toolkit application stubber.

Future work:
There is still a bit of work that is needed for the UI. In terms of immediate plans, I will next be adding:

  • Section pages to show prompts only for a specific section
  • Tighter control over which prompt to move next to based on wizard definition
  • Visibility for certain prompts based on a previous selection.

@codecov-io
Copy link

codecov-io commented Nov 17, 2020

Codecov Report

Merging #5728 (8639e4b) into wizard-improvements (f278855) will decrease coverage by 0.04%.
The diff coverage is 96.22%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           wizard-improvements    #5728      +/-   ##
=======================================================
- Coverage                93.47%   93.43%   -0.05%     
=======================================================
  Files                      254      258       +4     
  Lines                    20184    20283      +99     
=======================================================
+ Hits                     18867    18951      +84     
- Misses                    1317     1332      +15     
Impacted Files Coverage Δ
awscli/customizations/wizard/ui/selectmenu.py 24.46% <ø> (ø)
awscli/customizations/wizard/devcommands.py 82.35% <40.00%> (-5.89%) ⬇️
awscli/customizations/wizard/app.py 92.30% <92.30%> (ø)
awscli/customizations/configure/sso.py 100.00% <100.00%> (ø)
awscli/customizations/wizard/ui/__init__.py 71.05% <100.00%> (ø)
awscli/customizations/wizard/ui/layout.py 100.00% <100.00%> (ø)
awscli/customizations/wizard/ui/prompt.py 100.00% <100.00%> (ø)
awscli/customizations/wizard/ui/style.py 100.00% <100.00%> (ø)
awscli/autoprompt/factory.py 78.04% <0.00%> (-7.32%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f278855...8639e4b. Read the comment docs.

Copy link
Contributor

@vz10 vz10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks great.

Just have a couple of NIT-like suggestions/comments

if app_assertion:
failure_message_format = (
f'Incorrect action on key press "{key}": '
'{message}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add f on this iine as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that omission was on purpose. Mainly the {message} is filled out later when the AssertionError is propagated.


def _create_all_prompts(self, definition):
prompts = []
for _, step_definition in definition['plan'].items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably using .values() would be more clear

from prompt_toolkit.document import Document
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import (
Window, VSplit, Dimension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] I believe it fits in one line

self.container = self._get_answer_container()

def _get_answer_buffer(self):
return Buffer(name=f'{self._value_name}_answer_buffer')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the reason of giving name to this Buffer if we never use this name?

I was wondering if it makes sense to name the buffer just f'{self._value_name} and make keybindings global instead of injecting them into each WizardPrompt

Something like

def submit_current_answer(event):
    current_buffer = event.app.current_buffer.name
    event.app.values[current_buffer.name] = .current_buffer.text

@kb.add('tab')
@kb.add('enter')
def next_prompt(event):
    submit_current_answer(event)
    event.app.layout.focus_next()

@kb.add('s-tab')
def last_prompt(event):
    submit_current_answer(event)
    event.app.layout.focus_last()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I originally wanted to use the name but it was something that got missed after trying a couple of different approaches. Honestly the key tabbing logic is going to be going away in the next PR, specifically I'm going to introduce an abstraction that walks though the wizard prompts telling us what the current prompt is and what the next prompt will be. I do like the idea of making the keybindings global now though so I'll introduce a keybindings module to encompass the current logic and build off of it.

return VSplit(
[
WizardPromptDescription(
answer_buffer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concern about passing the reference to the buffer between containers, maybe it would be safer just to path its name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm just going to switch this to use the value name.

New prompttoolkit abstractions will be added underneath
this package
The layout currently just:
* Displays all prompts no matter if they should not be shown
* Allows you to type a answer to each prompt
* Allows you to tab through and back prompts
* Highlights prompt that has the current focus
This allows us to try out the new wizard format without
having to touch the actual wizard commands. In order to run
just type:

  aws cli-dev wizard-dev --run-wizard file://path/to/wizard.yml
This makes it easier to share with other features that will need
it such as wizards
To do this, it required updating the application stubber
with the following changes:

* Added the ability to make assertions instead of only being
  able to rely on True/False. This makes the error messages a
  bit more verbose and easier to make more complex assertions

* Added the ability to set the text of the current focused buffer.
  This allows for text to be inputted.

There are still more tests needed to be added here but they should
be added once the UI and wizard spec stabilizes.
It involved:
* Updating test cases to use the updated stubber methods
* Change all of the assertions to include some assertion in them
* Make more helper methods to make it easier to update assertions
  in the future
Specifically:
* Updated some styling on imports
* Added a new keybindings module to represent keybindings
  for the entire application and moved keybindings from
  individual prompts to it
* Reference buffers by value name to simplify required reference
  values
Copy link
Contributor

@vz10 vz10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. I like it 🏄‍♀️

@kyleknap kyleknap merged commit 85ef4fa into aws:wizard-improvements Nov 18, 2020
@kyleknap kyleknap deleted the improved-wizard-init branch November 18, 2020 03:01
kyleknap added a commit that referenced this pull request Nov 21, 2020
[v2] Initial groundwork for wizard improvements
kyleknap added a commit that referenced this pull request Nov 25, 2020
[v2] Initial groundwork for wizard improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants