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

feat: change from flags to arguments when passing path to a file or context name #59

Merged
merged 12 commits into from
Sep 13, 2021
Merged

feat: change from flags to arguments when passing path to a file or context name #59

merged 12 commits into from
Sep 13, 2021

Conversation

Souvikns
Copy link
Member

@Souvikns Souvikns commented Aug 31, 2021

Description
In this PR I am trying to shift from --file flag to input so now the validate command will look something like this - asyncapi validate <file-path|urlcontext-name>. As of now, we were relying on the useSpecFile hook to load the spec file according to availability. It was built in a way that any command in the future could use it load the spec file as all commands depend on the spec file in some way since we were using the --file flag. Now when we are shifting from flags to input, this hook is not needed.
Also, other commands will have different needs for accessing inputs. So I think we would be needing to create different hooks to load the spec file according to that specific command.

Amidst all this, some logic would be reusable like

  • If no input is passed and if the command is loading a single spec file then usage of the current context or autodetecting spec file from working directory.
  • If the input is passed checking if it is a valid local spec file path, URL, or context name.

Related issue(s)

See also #37

@derberg
Copy link
Member

derberg commented Aug 31, 2021

@Souvikns fyi GitHub has option to create a draft pull request

@Souvikns
Copy link
Member Author

@derberg should I make this a draft now?

@derberg
Copy link
Member

derberg commented Aug 31, 2021

Nah, it's ok, just remember next time, so you do not have to add any disclaimer in the description that PR is wip

@Souvikns
Copy link
Member Author

Souvikns commented Sep 2, 2021

@derberg I am ready for review.

Working on this PR I think the ContextService has a problem, but I don't know if that is a legit problem its something I feel, should I open an issue talking about this.

@derberg
Copy link
Member

derberg commented Sep 2, 2021

@Souvikns don't forget about docs and help commands 😉

as for the ContextService -> you definitely need to create an issue as I have no idea what are you referring too exactly 😄

@derberg
Copy link
Member

derberg commented Sep 7, 2021

  • when I do below, I don't get an error that the given option is not available and instead my default context is picked.
    asyncapi validate --context test2
      File: /xxx/test/docs/dummy.yml successfully validated!
    
  • when I do asyncapi validate /wrong/path/dummy.yml I get error with outdated help text
  • when I do asyncapi context add test /correct/path/dummy.ymlI get help message that has outdated help text

search in project for any mention of --file and --context

README.md Outdated Show resolved Hide resolved
@Souvikns
Copy link
Member Author

Souvikns commented Sep 8, 2021

When you do asyncapi validate --context test2 it loads the current context because now cli is loading from input and test2 is in options and the input is undefined which leads it load context from current.

Now --file and --context does not work if you want to load any specific context then you can do it like this asyncapi validate test2. I think removing every mention of --file and --context flags would help the users.

@derberg
Copy link
Member

derberg commented Sep 8, 2021

When you do asyncapi validate --context test2 it loads the current context because now cli is loading from input and test2 is in options and the input is undefined which leads it load context from current.

yes, but we need to have in place validation of options and notify users if they use not existing options, so we do not do what we think is better for users but tell what's wrong. You know what I mean? can be done as follow-up as this could be supported also by https://www.npmjs.com/package/levenshtein-edit-distance to not only tell users the command is wrong, but also try suggesting the correct one

@Souvikns
Copy link
Member Author

Souvikns commented Sep 8, 2021

yes, but we need to have in place validation of options and notify users if they use not existing options, so we do not do what we think is better for users but tell what's wrong. You know what I mean? can be done as follow-up as this could be supported also by https://www.npmjs.com/package/levenshtein-edit-distance to not only tell users the command is wrong, but also try suggesting the correct one

This is a good idea user experience will certainly increase. I will open a follow-up issue for this.

when I do asyncapi validate /wrong/path/dummy.yml I get error with outdated help text

This is error message that is being used in the validate component, It is also being reused for other instances where spec path is incorrect.

when I do asyncapi context add test /correct/path/dummy.ymlI get help message that has outdated help text

This is the new updated error before, it use to show that `file path does not exist. Do you reckon this could be improved, maybe with some ❌ icon in the beginning or something?

And for now I will update any document that mentions --file and --context and update it with parameters.

@derberg
Copy link
Member

derberg commented Sep 8, 2021

@Souvikns awesome, lemme know once you need me for another review round

@Souvikns
Copy link
Member Author

@Souvikns awesome, lemme know once you need me for another review round

@derberg it is ready to be reviewed.

@derberg derberg changed the title feat: shifting from flags to input for validation command feat: change from flags to arguments when passing path to a file or context name Sep 13, 2021
Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

🔥 🚀

You can merge it on your own. Make sure the commit that you will use when using squash&merge reflects the one from PR title
:shipit:

@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Souvikns Souvikns merged commit a39640a into asyncapi:master Sep 13, 2021
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants