summaryrefslogtreecommitdiff
path: root/go/internal/command/command.go
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-12-21 18:05:18 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2019-01-15 11:51:38 +0100
commit7215126b6674abd4b5ff6b97d30bab6c544bf8df (patch)
tree80afaa50573476962cd8b531678ddb8b77ae8c63 /go/internal/command/command.go
parent0cbbe1e3b555b3d62b2cb5a6a17c5c4992e3619d (diff)
downloadgitlab-shell-7215126b6674abd4b5ff6b97d30bab6c544bf8df.tar.gz
Allow enabling gitlab-shell "discover"-feature
This adds the possibility to enable features for GitLab shell. The first feature being recognized is "Discover": It's the command that is executed when running `ssh git@gitlab.example.com` and is called without a command. The gitlab key id or username is already parsed from the command line arguments. Currently we only support communicating with GitLab-rails using unix sockets. So features will not be enabled if the GitLab-url is using a different protocol. The url for this read from the config yaml. Pending ruby-specs have been added for the gitlab-shell command. Refactor to have separate command packages
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
+}