diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-07-29 15:56:00 +0800 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-07-31 12:03:37 +0800 |
commit | 3b0176df497263323da2fae793a79b568502e6db (patch) | |
tree | f4ff3e232bc3717c539d73a4f0460d6d12b4a6de /go/internal/command/command.go | |
parent | aab85f3600caf04b491d6ca4fc3f0f004d9e3fc0 (diff) | |
download | gitlab-shell-3b0176df497263323da2fae793a79b568502e6db.tar.gz |
Support different CommandArgs type
`CommandArgs` has been renamed to `Shell`.
An interface has been added that includes `Executable()` and
`Arguments()` method. The `BaseArgs` implement this methods
and should be embeeded in each type.
Diffstat (limited to 'go/internal/command/command.go')
-rw-r--r-- | go/internal/command/command.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/go/internal/command/command.go b/go/internal/command/command.go index 77feda8..66bed6f 100644 --- a/go/internal/command/command.go +++ b/go/internal/command/command.go @@ -23,16 +23,27 @@ func New(arguments []string, config *config.Config, readWriter *readwriter.ReadW return nil, err } - if config.FeatureEnabled(string(args.CommandType)) { - if cmd := buildCommand(args, config, readWriter); cmd != nil { - return cmd, nil - } + if cmd := buildCommand(args, config, readWriter); cmd != nil { + return cmd, nil } return &fallback.Command{RootDir: config.RootDir, Args: args}, nil } -func buildCommand(args *commandargs.CommandArgs, config *config.Config, readWriter *readwriter.ReadWriter) Command { +func buildCommand(args commandargs.CommandArgs, config *config.Config, readWriter *readwriter.ReadWriter) Command { + switch args.Executable() { + case commandargs.GitlabShell: + return buildShellCommand(args.(*commandargs.Shell), config, readWriter) + } + + return nil +} + +func buildShellCommand(args *commandargs.Shell, config *config.Config, readWriter *readwriter.ReadWriter) Command { + if !config.FeatureEnabled(string(args.CommandType)) { + return nil + } + switch args.CommandType { case commandargs.Discover: return &discover.Command{Config: config, Args: args, ReadWriter: readWriter} |