summaryrefslogtreecommitdiff
path: root/go/internal/command/command.go
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-01-15 23:36:21 +0000
committerNick Thomas <nick@gitlab.com>2019-01-15 23:36:21 +0000
commit1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258 (patch)
treec246e5b43a1e7b5744e10e75d6ed125629f45936 /go/internal/command/command.go
parent6c5b195353a632095d7f672d28b9985fd879b077 (diff)
parentd762f4ec9ea35cb00309b41ad60055cd3c5709ba (diff)
downloadgitlab-shell-1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258.tar.gz
Merge branch 'bvl-feature-flag-commands' into 'master'
Parse commands to enable feature flags See merge request gitlab-org/gitlab-shell!270
Diffstat (limited to 'go/internal/command/command.go')
-rw-r--r--go/internal/command/command.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/go/internal/command/command.go b/go/internal/command/command.go
new file mode 100644
index 0000000..cb2acdc
--- /dev/null
+++ b/go/internal/command/command.go
@@ -0,0 +1,35 @@
+package command
+
+import (
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/discover"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
+)
+
+type Command interface {
+ Execute() error
+}
+
+func New(arguments []string, config *config.Config) (Command, error) {
+ args, err := commandargs.Parse(arguments)
+
+ if err != nil {
+ return nil, err
+ }
+
+ if config.FeatureEnabled(string(args.CommandType)) {
+ return buildCommand(args, config), nil
+ }
+
+ return &fallback.Command{}, nil
+}
+
+func buildCommand(args *commandargs.CommandArgs, config *config.Config) Command {
+ switch args.CommandType {
+ case commandargs.Discover:
+ return &discover.Command{Config: config, Args: args}
+ }
+
+ return nil
+}