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

Add informations on cli output about module when fact or operation was not found #1244

Draft
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

maisim
Copy link
Contributor

@maisim maisim commented Nov 22, 2024

Hello folks,

If the operation or fact was not found, it will display the ones available, and if no one is available, Warn the user about the possibility that he have a py file or a folder with the same name as the module

If you have a directory wich have the same name as the pyinfra module you want to use, pyinfra will try to look inside form the operations/facts (wich seems to be the wanted behavior)

So I added a message to inform about this possibility if the module/fact is not found:

find . -name incus
./incus
pyinfra inventory.py --debug --limit=lx1 fact incus.IncusProfiles
--> pyinfra error: No such attribute in module incus: IncusProfiles
No facts found. Maybe you have a file or folder named `incus` in the current folder ?

In the same time I added this:

pyinfra inventory.py --debug --limit=lx1 fact incus.IncusProfilesNOEXIST
--> pyinfra error: No such attribute in module incus: IncusProfilesNOEXIST
Available facts in module are: IncusInstances, IncusProfiles, IncusTestFact

This is a suggestion, tell me what you think.

"No such attribute in module server: NotAFact",
(
"No such attribute in module server: NotAFact\n"
"Available facts in module are: User, Home, Path, TmpDir, Hostname, Kernel, "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each update will implies an updtate of the test, maybe use a regex slould be better?

@maisim maisim force-pushed the 3.x_cli_show_infos_to_understand_why_op_or_fact_was_not_found branch 2 times, most recently from 6936791 to fce49ad Compare November 25, 2024 08:36
@maisim maisim marked this pull request as draft November 25, 2024 08:43
@maisim
Copy link
Contributor Author

maisim commented Nov 25, 2024

It does not work as expected for operations in case of misspelling

@maisim maisim force-pushed the 3.x_cli_show_infos_to_understand_why_op_or_fact_was_not_found branch from fce49ad to b89c2f4 Compare November 25, 2024 09:22
If the operation or fact is not found, it will display the ones
available, and if no one is avaible, Warn the user about the possibility
that he have a py file or a folder with the same name as the module
Use of regex to avoid having to update the cli tests each time the operations and facts used in them are modified
@maisim maisim force-pushed the 3.x_cli_show_infos_to_understand_why_op_or_fact_was_not_found branch from b89c2f4 to 8b752b1 Compare November 25, 2024 10:25
Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

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

@maisim this is awesome! Really big QoL improvement.

It does not work as expected for operations in case of misspelling

What do you mean by this? I'll have a play around with the branch when I get the chance, just wondering.

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.

2 participants