Skip to content

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

Merged
Souvikns merged 12 commits into
asyncapi:masterfrom
Souvikns:remove-file-flag
Sep 13, 2021
Merged

Souvikns merged 12 commits into
asyncapi:masterfrom
Souvikns:remove-file-flag

Conversation

@Souvikns

@Souvikns Souvikns commented Aug 31, 2021 •

Copy link
Copy Markdown
Member

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

derberg commented Aug 31, 2021

Copy link
Copy Markdown
Member

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

@Souvikns

Copy link
Copy Markdown
Member Author

@derberg should I make this a draft now?

@derberg

derberg commented Aug 31, 2021

Copy link
Copy Markdown
Member

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

Souvikns commented Sep 2, 2021

Copy link
Copy Markdown
Member Author

@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

derberg commented Sep 2, 2021

Copy link
Copy Markdown
Member

@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

derberg commented Sep 7, 2021

Copy link
Copy Markdown
Member
  • 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

Comment thread README.md Resolved
@Souvikns

Souvikns commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

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

derberg commented Sep 8, 2021

Copy link
Copy Markdown
Member

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

Souvikns commented Sep 8, 2021

Copy link
Copy Markdown
Member Author

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

derberg commented Sep 8, 2021

Copy link
Copy Markdown
Member

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

@Souvikns

Copy link
Copy Markdown
Member Author

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

@derberg it is ready to be reviewed.

@Souvikns
Souvikns requested a review from derberg September 13, 2021 05:44
@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

@derberg derberg left a comment

Copy link
Copy Markdown
Member

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:

@sonarqubecloud

Copy link
Copy Markdown

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
Copy Markdown
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.

3 participants