diff --git a/cli/azd/.vscode/cspell-azd-dictionary.txt b/cli/azd/.vscode/cspell-azd-dictionary.txt index 3b42afecb61..ec26a8a1c1f 100644 --- a/cli/azd/.vscode/cspell-azd-dictionary.txt +++ b/cli/azd/.vscode/cspell-azd-dictionary.txt @@ -28,6 +28,7 @@ godotenv golangci ldflags mgmt +mgutz nodeapp nolint omitempty diff --git a/cli/azd/cmd/deploy.go b/cli/azd/cmd/deploy.go index 109ca758192..406a2fde6b4 100644 --- a/cli/azd/cmd/deploy.go +++ b/cli/azd/cmd/deploy.go @@ -17,8 +17,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/project" "github.com/azure/azure-dev/cli/azd/pkg/spin" "github.com/azure/azure-dev/cli/azd/pkg/tools" - "github.com/fatih/color" - "github.com/mattn/go-colorable" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/theckman/yacspin" @@ -190,8 +188,14 @@ func (d *deployAction) Run(ctx context.Context, cmd *cobra.Command, args []strin } for _, resourceGroup := range resourceGroups { - resourcesGroupsURL := color.HiBlueString("https://portal.azure.com/#@/resource/subscriptions/%s/resourceGroups/%s/overview", env.GetSubscriptionId(), resourceGroup) - fmt.Fprintf(colorable.NewColorableStdout(), "View the resources created under the resource group %s in Azure Portal:\n%s", color.CyanString(resourceGroup), resourcesGroupsURL) + resourcesGroupsURL := withLinkFormat( + "https://portal.azure.com/#@/resource/subscriptions/%s/resourceGroups/%s/overview", + env.GetSubscriptionId(), + resourceGroup) + printWithStyling( + "View the resources created under the resource group %s in Azure Portal:\n%s", + withHighLightFormat(resourceGroup), + resourcesGroupsURL) } return nil @@ -201,7 +205,7 @@ func reportServiceDeploymentResultInteractive(s *yacspin.Spinner, svc *project.S var builder strings.Builder for _, endpoint := range sdr.Endpoints { - builder.WriteString(fmt.Sprintf(" - Endpoint: %s\n", color.HiBlueString(endpoint))) + builder.WriteString(fmt.Sprintf(" - Endpoint: %s\n", withLinkFormat(endpoint))) } stopMessage := fmt.Sprintf("\nDeployed service %s\n%s", svc.Config.Name, builder.String()) diff --git a/cli/azd/cmd/infra_create.go b/cli/azd/cmd/infra_create.go index 17477617b7d..6566fb4af7f 100644 --- a/cli/azd/cmd/infra_create.go +++ b/cli/azd/cmd/infra_create.go @@ -19,8 +19,6 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/spin" "github.com/azure/azure-dev/cli/azd/pkg/tools" "github.com/drone/envsubst" - "github.com/fatih/color" - "github.com/mattn/go-colorable" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/theckman/yacspin" @@ -229,8 +227,13 @@ func (ica *infraCreateAction) Run(ctx context.Context, cmd *cobra.Command, args if interactive { deploymentSlug := azure.SubscriptionDeploymentRID(env.GetSubscriptionId(), env.GetEnvName()) - deploymentURL := color.HiBlueString("https://portal.azure.com/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/%s\n\n", url.PathEscape(deploymentSlug)) - fmt.Fprintf(colorable.NewColorableStdout(), "Provisioning Azure resources can take some time.\n\nYou can view detailed progress in the Azure Portal:\n%s", deploymentURL) + deploymentURL := withLinkFormat( + "https://portal.azure.com/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/%s\n\n", + url.PathEscape(deploymentSlug)) + printWithStyling( + "Provisioning Azure resources can take some time.\n\nYou can view detailed progress in the Azure Portal:\n%s", + deploymentURL) + //fmt.Fprintf(colorable.NewColorableStdout(), "Provisioning Azure resources can take some time.\n\nYou can view detailed progress in the Azure Portal:\n%s", deploymentURL) err = spin.RunWithUpdater("Creating Azure resources ", deployAndReportProgress, func(s *yacspin.Spinner, deploySuccess bool) { diff --git a/cli/azd/cmd/util.go b/cli/azd/cmd/util.go index 77b74a31fac..679b87aa508 100644 --- a/cli/azd/cmd/util.go +++ b/cli/azd/cmd/util.go @@ -20,7 +20,9 @@ import ( "github.com/azure/azure-dev/cli/azd/pkg/environment" "github.com/azure/azure-dev/cli/azd/pkg/templates" "github.com/azure/azure-dev/cli/azd/pkg/tools" + "github.com/fatih/color" "github.com/mattn/go-isatty" + "github.com/mgutz/ansi" ) type Asker func(p survey.Prompt, response interface{}) error @@ -550,3 +552,22 @@ func ensureProject(path string) error { return nil } + +// withLinkFormat creates string with hyperlink-looking color +func withLinkFormat(link string, a ...interface{}) string { + // See ansi colors: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors + // ansi code `30` is the one that matches the survey selection + return ansi.Color(fmt.Sprintf(link, a...), "30") +} + +// withHighLightFormat creates string with highlight-looking color +func withHighLightFormat(text string, a ...interface{}) string { + return color.CyanString(text, a...) +} + +// printWithStyling prints text to stdout and handles Windows terminals to support +// escape chars from the text for adding style (color, font, etc) +func printWithStyling(text string, a ...interface{}) { + colorTerminal := color.New() + colorTerminal.Printf(text, a...) +} diff --git a/go.mod b/go.mod index edf3d684cd9..23726b5d148 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/fatih/color v1.13.0 github.com/joho/godotenv v1.4.0 github.com/magefile/mage v1.12.1 - github.com/mattn/go-colorable v0.1.12 github.com/mattn/go-isatty v0.0.14 + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b github.com/otiai10/copy v1.7.0 github.com/pbnj/go-open v0.1.1 github.com/sethvargo/go-retry v0.2.3 @@ -28,8 +28,8 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/pkg/errors v0.8.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect