From d88d185b2b71fb6a271c76c37f7c27f73a3abaa2 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sun, 14 Feb 2021 20:12:36 -0300 Subject: [PATCH] feat: prompt select for scope if scope.values is defined --- cmd/git-sv/handlers.go | 2 +- cmd/git-sv/prompt.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index 07178c3..fcb6b87 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -270,7 +270,7 @@ func commitHandler(cfg Config, git sv.Git, messageProcessor sv.MessageProcessor) return err } - scope, err := promptScope() + scope, err := promptScope(cfg.CommitMessage.Scope.Values) if err != nil { return err } diff --git a/cmd/git-sv/prompt.go b/cmd/git-sv/prompt.go index 0f935fd..9f008fd 100644 --- a/cmd/git-sv/prompt.go +++ b/cmd/git-sv/prompt.go @@ -46,7 +46,14 @@ func promptType() (commitType, error) { return items[i], nil } -func promptScope() (string, error) { +func promptScope(values []string) (string, error) { + if len(values) > 0 { + selected, err := promptSelect("scope", values, nil) + if err != nil { + return "", err + } + return values[selected], nil + } return promptText("scope", "^[a-z0-9-]*$", "") }