ref: suggest management and check needed flags

only display the hints in main case, without progress, output or push
flags

Signed-off-by: Yves Brissaud <yves.brissaud@docker.com>
This commit is contained in:
Yves Brissaud 2023-06-12 10:18:54 +02:00
Родитель 62c2e00acc
Коммит 90058ec005
Не найден ключ, соответствующий данной подписи
2 изменённых файлов: 27 добавлений и 8 удалений

Просмотреть файл

@ -111,16 +111,18 @@ func Exec(_ *cobra.Command) {
}
commandArgs := os.Args[1:]
command := metrics.GetCommand(commandArgs)
if (command == "build" || command == "pull") && !metrics.HasQuietFlag(commandArgs) {
var image string
if command == "pull" {
image = pulledImageFromArgs(commandArgs)
if !metrics.HasQuietFlag(commandArgs) {
switch command {
case "build": // only on regular build, not on buildx build
displayScoutQuickViewSuggestMsgOnBuild(commandArgs)
case "pull":
displayScoutQuickViewSuggestMsgOnPull(commandArgs)
case "login":
displayPATSuggestMsg(commandArgs)
default:
}
displayScoutQuickViewSuggestMsg(image)
}
if command == "login" && !metrics.HasQuietFlag(commandArgs) {
displayPATSuggestMsg(commandArgs)
}
metricsClient.Track(
metrics.CmdResult{
ContextType: store.DefaultContextType,

Просмотреть файл

@ -22,6 +22,8 @@ import (
"strconv"
"strings"
"github.com/docker/compose/v2/pkg/utils"
"github.com/fatih/color"
)
@ -34,6 +36,21 @@ func isDockerScoutHintsEnabled() bool {
return err != nil || enabled
}
func displayScoutQuickViewSuggestMsgOnPull(args []string) {
image := pulledImageFromArgs(args)
displayScoutQuickViewSuggestMsg(image)
}
func displayScoutQuickViewSuggestMsgOnBuild(args []string) {
// only display the hint in the main case, build command and not buildx build, no output flag, no progress flag, no push flag
if utils.StringContains(args, "--output") || utils.StringContains(args, "-o") ||
utils.StringContains(args, "--progress") ||
utils.StringContains(args, "--push") {
return
}
displayScoutQuickViewSuggestMsg("")
}
func displayScoutQuickViewSuggestMsg(image string) {
if !isDockerScoutHintsEnabled() {
return