github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/pkg/command/command.go (about)

     1  // Package command provides the common interface for all commands.
     2  package command
     3  
     4  // The Command interface provides a common interface for commands, simplifying
     5  // the process of providing cross-platform and OS-specific commands.
     6  type Command interface {
     7  	// Name is the name of the command, what will appear in the help
     8  	// documentation, and what the operator will type to run the command.
     9  	Name() string
    10  	// Run performs the command's operation.
    11  	Run(clientID string, jobID string, args []string) (string, error)
    12  }
    13  
    14  var availableCommands = map[string]Command{}
    15  
    16  // RegisterCommand registers a command for use by the implant.
    17  //
    18  // This is typically done immediately after declaring the command to make it
    19  // easy to create the list of available commands at compile time for the
    20  // target OS.
    21  func RegisterCommand(cmd Command) {
    22  	availableCommands[cmd.Name()] = cmd
    23  }
    24  
    25  // GetCommand returns the command with the given name or nil if it hasn't
    26  // been registered or otherwise doesn't exist.
    27  func GetCommand(name string) Command {
    28  	return availableCommands[name]
    29  }