vue-command icon indicating copy to clipboard operation
vue-command copied to clipboard

Feature: Add options per command

Open Phoetaim opened this issue 5 years ago • 4 comments

Hi,

I wanted to emulate a terminal with some basic commands like ls and cd. I used vue-command to do it however I have a problem with the options : parser-options only takes 1 JSON and in the handle for getOpts, "this.parserOptions" is used and not "this.parserOptions[program]". Could it be possible to change it so we can define options per command like: { ls: {boolean:["l","i"]}, cd: {boolean:["r","g"] }

Thank you

PS: the code I saw is in src/mixins/handle.js line 87

Phoetaim avatar Sep 23 '20 09:09 Phoetaim

That's interesting. That would mean first a breaking change, since commands are objects instead of functions. Second, and that's the reason why I sticked with functions, it would mean that the user needs to pass an object with unknown key values pairs. Which I disliked because there is no code autocompletion for they keys/values.

I guess the result of your approach would be something like:

{
  ls: {
    command: () => console.info('ls'),
    boolean: ['l', 'i']
  }
}

Rewriting the library in TypeScript could solve the problem or we introduce another property map like:

const options = new Map()
map.set('ls', { boolean: ['l', 'i'] })

This way, the command can stay a function.

Another important aspect is that there is no native way to process options so far. You have to write your autocompletion resolver by yourself (no time and sensible approach, yet).

Or maybe I understand you totally wrong :) Could you explain maybe a little bit more the code change that would come with your suggestion?

ndabAP avatar Sep 23 '20 09:09 ndabAP

I was thinking of the second way mostly. In your demo code you have: options:{ long:{ls:...} } I would add another variable in data: parserOptions:{ ls:{your options for ls}, cd:{same for cd}} then give it to the :parser-options during the creating of the vuecommand component.

Finally, in Vue-command, when you parse the request, with getOpts, I would give only the options corresponding to the right command with this.parserOptions[command].

Phoetaim avatar Sep 23 '20 10:09 Phoetaim

@Phoetaim would you make a PR for it?

ndabAP avatar Sep 27 '20 17:09 ndabAP

Done

Phoetaim avatar Sep 28 '20 08:09 Phoetaim