cli icon indicating copy to clipboard operation
cli copied to clipboard

fix: help command

Open sambhavgupta0705 opened this issue 2 years ago • 38 comments
trafficstars

Description

  • ...
  • ...
  • ...

Related issue(s)

#559

sambhavgupta0705 avatar May 25 '23 08:05 sambhavgupta0705

@Souvikns Just a quick question before i bail out, how are we supposed to prevent the @oclif/plugin-not-found from triggering, inside the hook that we are working with ?

kaushik-rishi avatar May 25 '23 08:05 kaushik-rishi

The plugin we are using right now is actually a hook, you can use that as an example https://github.com/oclif/plugin-not-found

Souvikns avatar May 25 '23 08:05 Souvikns

The plugin we are using right now is actually a hook, you can use that as an example https://github.com/oclif/plugin-not-found

But we would still need the oclif/plugin-not-found for any other user entered commands which donot exist right ?

We basically need this new hook on top of oclif/plugin-not-found as far as i get it. please correct me.

kaushik-rishi avatar May 25 '23 08:05 kaushik-rishi

image This is the output @Souvikns

sambhavgupta0705 avatar May 25 '23 08:05 sambhavgupta0705

The plugin we are using right now is actually a hook, you can use that as an example https://github.com/oclif/plugin-not-found

yes I read the blog and the hook was setup inside the plugin

sambhavgupta0705 avatar May 25 '23 08:05 sambhavgupta0705

I don't think we need the old plugin we are replacing it with our custom hook

Souvikns avatar May 25 '23 08:05 Souvikns

image

This is the output @Souvikns

https://github.com/asyncapi/cli/blob/479c31d8c4652831b0c6472ba49a77e8cf7b189d/src/hooks/command_not_found/help-command-handler.ts#L4

I just logged the options passed for reference. You can build on top of this.

kaushik-rishi avatar May 25 '23 08:05 kaushik-rishi

@kaushik-rishi I think we should not console.log this whole message and just console help command doesn't exist try --help

sambhavgupta0705 avatar May 25 '23 08:05 sambhavgupta0705

That output is comping from logging the opts right, now you just have to have a custom warning about it. I think if you see that log that means that the hook is connected to the CLI

Souvikns avatar May 25 '23 08:05 Souvikns

@sambhavgupta0705 yes, i just logged it for your reference. i've written an if condition below it inside of which you can build.

kaushik-rishi avatar May 25 '23 08:05 kaushik-rishi

@sambhavgupta0705 please remove the errors folder. just reminding.

kaushik-rishi avatar May 25 '23 10:05 kaushik-rishi

@sambhavgupta0705 please remove the errors folder. just reminding.

okay the one made by me

sambhavgupta0705 avatar May 25 '23 14:05 sambhavgupta0705

@Souvikns the PR is ready for review

sambhavgupta0705 avatar May 25 '23 14:05 sambhavgupta0705

package-lock.json shouldn't technically change.

As we didn't install or uninstall any package I think we can safely revert package-lock.json changes.

kaushik-rishi avatar May 25 '23 15:05 kaushik-rishi

I don't think we need the old plugin we are replacing it with our custom hook

@Souvikns need your suggestions 🙂

i understand, but what about the fallback for other commands, the hook developed here is handling just the help command and suggesting the user to use --help. What if i use something like asyncapi generte (intentional typo), we would still need the plugin-not-found to give us a fallback option to suggestions from the plugin right ?

image


Also, @sambhavgupta0705 can we rather find a way to just bail out and exit after the console.log in the hook, not to forward the entire case to plugin-not-found module ?

image

kaushik-rishi avatar May 25 '23 15:05 kaushik-rishi

Yes we can add .exit functionality here.

sambhavgupta0705 avatar May 25 '23 15:05 sambhavgupta0705

@sambhavgupta0705 for your reference. follow the last line of this documentation https://oclif.io/docs/hooks. you can use this.exit() to exit out instead of going further.

Try it once, you might see other issues. Just a hint forward. 🙂

let @Souvikns confirm if this is what we are looking forward to do.

kaushik-rishi avatar May 25 '23 16:05 kaushik-rishi

@kaushik-rishi I tried adding this.exit() but the plugin console was always get printed

sambhavgupta0705 avatar May 25 '23 18:05 sambhavgupta0705

@kaushik-rishi I tried adding this.exit() but the plugin console was always get printed

It is probably due to asynchronous nauigure, i'm afraid i don't have a solution for this right away.

I can explain the situation better. May be it's like once the hook is triggered both the plugins (the one we wrote and the plugin-not-found) and being called at the same time. It is exiting fine but before exiting it's printing the first line of the plugin-not-founds prompt.

kaushik-rishi avatar May 25 '23 18:05 kaushik-rishi

Yess

sambhavgupta0705 avatar May 25 '23 18:05 sambhavgupta0705

Yess

I have a couple of ideas, Let @Souvikns catch up and review the discussion uptill now. 🙂

We can easily make our own hook for handling every command that isn't found. Let's carry it further.

kaushik-rishi avatar May 25 '23 19:05 kaushik-rishi

Yeah, the plugin used to suggest or at least try to suggest an alternative command if one is wrong, I think we can build this feature, you can take inspiration from the plugin if you want.

Souvikns avatar May 26 '23 07:05 Souvikns

Yeah, the plugin used to suggest or at least try to suggest an alternative command if one is wrong, I think we can build this feature, you can take inspiration from the plugin if you want.

@Souvikns I'm not very aware of the licenes, but looking at this (licence), are we allowed to copy the code into our hook and then modify as per our requirements ?

kaushik-rishi avatar May 26 '23 08:05 kaushik-rishi

You write the code, and you can take inspiration from it, and write it in your own way, I don't know about the license, @derberg are we breaking any rules here?

Souvikns avatar May 26 '23 08:05 Souvikns

You write the code, and you can take inspiration from it, and write it in your own way, I don't know about the license, @derberg are we breaking any rules here?

If we have the ability to re-use the code, we can skip rewriting it :slightly_smiling_face: . Let @derberg clarify. We can write our own handler in the worst case, Won't be that difficult.

kaushik-rishi avatar May 26 '23 08:05 kaushik-rishi

@sambhavgupta0705 @kaushik-rishi, @derberg is not available right now, you can go ahead and start building the suggestion feature, no need to reuse but if you want you can take inspiration from the existing library.

Souvikns avatar Jun 06 '23 12:06 Souvikns

Sure @Souvikns

kaushik-rishi avatar Jun 06 '23 12:06 kaushik-rishi

@sambhavgupta0705 @kaushik-rishi, @derberg is not available right now, you can go ahead and start building the suggestion feature, no need to reuse but if you want you can take inspiration from the existing library.

Yup just busy with some work,will start working on this by this week.

sambhavgupta0705 avatar Jun 08 '23 07:06 sambhavgupta0705

hey @kaushik-rishi ,what other changes do we need to do?

sambhavgupta0705 avatar Jun 10 '23 05:06 sambhavgupta0705

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
1.0% 1.0% Duplication

sonarqubecloud[bot] avatar Jun 21 '23 17:06 sonarqubecloud[bot]