desertbit/grumble

how do i delete a command?

sairson opened this issue · 9 comments

How do I delete a command?
To do this, I added a del function to the source code

func (c *Commands)Del(name string) { for i,cmd := range c.list { if cmd.Name == name { c.list = append(c.list[:i],c.list[i+1:]...) } } }

Hi
Could you describe me the use case for this feature?

image

I may need to hide or delete registered commands during execution, and I find that you do not have the removal function, which means that I can only keep registering commands, but cannot remove them

I have added a section to your source code that can be used to delete commands that have already been registered

image

I see. We have never needed something like that before. Would it be possible that instead of conditionally deleting a command, you conditionally add them?

But I think that having a function that deletes commands doesn't affect the program's functionality, and instead, it can be a helpful way for some people (like me). Of course it is possible to add a conditional command, but I find it more effective to remove a command because the program is required at some point

r0l1 commented

Instead of deleting/adding commands, what do you think about following approach:

grumble.Command{
    Name:      "daemon",
    Help:      "run the daemon",
    Aliases:   []string{"run"},

    Active: func() bool {
        // Executed to check the command active status.
        // ...
        return false;
    },
   // ...
}

I think this is a good approach, but adding a delete operation is not too much, because some people may have different requirements at the time of writing, and if you can add the above method, it is also easy to hide and reality the command line,thanks

We will add it!

remove command has been added