From 1e8d5279333c1a8673548546726155c936c09f99 Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Fri, 3 May 2024 17:00:02 +0000 Subject: [PATCH 1/9] Test aks --- cli/azd/internal/repository/detect_confirm_apphost.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/azd/internal/repository/detect_confirm_apphost.go b/cli/azd/internal/repository/detect_confirm_apphost.go index ad227e0dfa3..c724de68903 100644 --- a/cli/azd/internal/repository/detect_confirm_apphost.go +++ b/cli/azd/internal/repository/detect_confirm_apphost.go @@ -80,7 +80,7 @@ func (d *detectConfirmAppHost) render(ctx context.Context) error { d.console.Message( ctx, "azd will generate the files necessary to host your app on Azure using "+color.MagentaString( - "Azure Container Apps", + "Azure Kubernetes Service", )+".\n", ) From 05b06f86c36e3e07a25b26cca839c7bd505791de Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:00:49 +0000 Subject: [PATCH 2/9] --query first --- cli/azd/.vscode/launch.json | 4 +- cli/azd/cmd/env.go | 3 +- cli/azd/cmd/middleware/query.go | 65 ++++++++++++++++++++++ cli/azd/cmd/root.go | 1 + cli/azd/internal/global_command_options.go | 2 + go.mod | 1 + go.sum | 3 + 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 cli/azd/cmd/middleware/query.go diff --git a/cli/azd/.vscode/launch.json b/cli/azd/.vscode/launch.json index 1123a587f3d..ed0906eb8a6 100644 --- a/cli/azd/.vscode/launch.json +++ b/cli/azd/.vscode/launch.json @@ -32,14 +32,14 @@ "program": "${workspaceFolder}", "console": "integratedTerminal", "args": [ - "auth", "login" + "env", "list", "-o", "json", "-q", "[?IsDefault].DotEnvPath" //"pipeline", "config", "--principal-name", "foo", "--provider", "github" //"package", "api", "--debug" //"provision" //"up" //"env", "new" ], - //"cwd": "~/workspace/cwd/path", + "cwd": "/workspaces/todo-csharp-sql", // "env": { // "INT_TAG_VALUE":"1989" // } diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index fe8d9beb4e4..241291673a3 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -10,6 +10,7 @@ import ( "io" "github.com/azure/azure-dev/cli/azd/cmd/actions" + "github.com/azure/azure-dev/cli/azd/cmd/middleware" "github.com/azure/azure-dev/cli/azd/internal" "github.com/azure/azure-dev/cli/azd/pkg/account" "github.com/azure/azure-dev/cli/azd/pkg/environment" @@ -61,7 +62,7 @@ func envActions(root *actions.ActionDescriptor) *actions.ActionDescriptor { ActionResolver: newEnvListAction, OutputFormats: []output.Format{output.JsonFormat, output.TableFormat}, DefaultFormat: output.TableFormat, - }) + }).UseMiddleware("query", middleware.NewQueryMiddleware) group.Add("refresh", &actions.ActionDescriptorOptions{ Command: newEnvRefreshCmd(), diff --git a/cli/azd/cmd/middleware/query.go b/cli/azd/cmd/middleware/query.go new file mode 100644 index 00000000000..40d375ab963 --- /dev/null +++ b/cli/azd/cmd/middleware/query.go @@ -0,0 +1,65 @@ +package middleware + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/azure/azure-dev/cli/azd/cmd/actions" + "github.com/azure/azure-dev/cli/azd/internal" + "github.com/jmespath/go-jmespath" +) + +type QueryMiddleware struct { + global *internal.GlobalCommandOptions +} + +func (m *QueryMiddleware) Run(ctx context.Context, next NextFn) (*actions.ActionResult, error) { + // Execute the next middleware or action in the chain + fmt.Println(m.global.Query) + result, err := next(ctx) + if err != nil { + return nil, err + } + + if m.global.Query == "" { + return result, nil + } + + // Convert the result to JSON + resultJSON, err := json.Marshal(result) + if err != nil { + return nil, fmt.Errorf("marshalling action result: %w", err) + } + + // Apply the JMESPath query + var jsonResult interface{} + err = json.Unmarshal(resultJSON, &jsonResult) + if err != nil { + return nil, fmt.Errorf("unmarshalling action result: %w", err) + } + + filteredResult, err := jmespath.Search(m.global.Query, jsonResult) + if err != nil { + return nil, fmt.Errorf("applying JMESPath query: %w", err) + } + + // Convert the filtered result back to an ActionResult + filteredResultJSON, err := json.Marshal(filteredResult) + if err != nil { + return nil, fmt.Errorf("marshalling filtered result: %w", err) + } + + var actionResult actions.ActionResult + err = json.Unmarshal(filteredResultJSON, &actionResult) + if err != nil { + return nil, fmt.Errorf("unmarshalling filtered result: %w", err) + } + + return &actionResult, nil +} + +// NewQueryMiddleware is the registration function for the QueryMiddleware +func NewQueryMiddleware(global *internal.GlobalCommandOptions) Middleware { + return &QueryMiddleware{global: global} +} diff --git a/cli/azd/cmd/root.go b/cli/azd/cmd/root.go index d38ea8cc78c..7dc7bfc95cf 100644 --- a/cli/azd/cmd/root.go +++ b/cli/azd/cmd/root.go @@ -99,6 +99,7 @@ func NewRootCmd( "no-prompt", false, "Accepts the default value instead of prompting, or it fails if there is no default.") + rootCmd.PersistentFlags().StringVarP(&opts.Query, "query", "q", "", "Run jmespath query on results") // The telemetry system is responsible for reading these flags value and using it to configure the telemetry // system, but we still need to add it to our flag set so that when we parse the command line with Cobra we diff --git a/cli/azd/internal/global_command_options.go b/cli/azd/internal/global_command_options.go index 009940df835..0d71eae9805 100644 --- a/cli/azd/internal/global_command_options.go +++ b/cli/azd/internal/global_command_options.go @@ -25,4 +25,6 @@ type GlobalCommandOptions struct { // like learn.microsoft.com. This is set directly when calling NewRootCmd // and not bound to any command flags. GenerateStaticHelp bool + + Query string } diff --git a/go.mod b/go.mod index 959329bace2..454980458b9 100644 --- a/go.mod +++ b/go.mod @@ -82,6 +82,7 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149 // indirect diff --git a/go.sum b/go.sum index d666fc23a2b..7f5349214f4 100644 --- a/go.sum +++ b/go.sum @@ -343,6 +343,9 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= From 42ceb2cbb78468bb3c66e632416c2a69d0224899 Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:35:21 +0000 Subject: [PATCH 3/9] add -q impl --- cli/azd/cmd/env.go | 3 +-- cli/azd/cmd/root.go | 1 - .../testdata/TestUsage-azd-auth-login.snap | 7 +++--- .../testdata/TestUsage-azd-auth-logout.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-auth.snap | 7 +++--- .../testdata/TestUsage-azd-config-get.snap | 7 +++--- .../TestUsage-azd-config-list-alpha.snap | 7 +++--- .../testdata/TestUsage-azd-config-reset.snap | 7 +++--- .../testdata/TestUsage-azd-config-set.snap | 7 +++--- .../testdata/TestUsage-azd-config-show.snap | 7 +++--- .../testdata/TestUsage-azd-config-unset.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-config.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-deploy.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-down.snap | 7 +++--- .../TestUsage-azd-env-get-values.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-env-list.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-env-new.snap | 7 +++--- .../testdata/TestUsage-azd-env-refresh.snap | 7 +++--- .../testdata/TestUsage-azd-env-select.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-env-set.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-env.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-hooks-run.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-hooks.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-init.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-monitor.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-package.snap | 7 +++--- .../TestUsage-azd-pipeline-config.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-pipeline.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-provision.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-restore.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-show.snap | 7 +++--- .../testdata/TestUsage-azd-template-list.snap | 7 +++--- .../testdata/TestUsage-azd-template-show.snap | 7 +++--- .../TestUsage-azd-template-source-add.snap | 7 +++--- .../TestUsage-azd-template-source-list.snap | 7 +++--- .../TestUsage-azd-template-source-remove.snap | 7 +++--- .../TestUsage-azd-template-source.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-template.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd-up.snap | 7 +++--- .../cmd/testdata/TestUsage-azd-version.snap | 7 +++--- cli/azd/cmd/testdata/TestUsage-azd.snap | 11 +++++---- cli/azd/pkg/input/console_test.go | 13 ++++++++++- cli/azd/pkg/output/formatter.go | 6 +++-- cli/azd/pkg/output/json.go | 23 +++++++++++++++---- cli/azd/pkg/output/parameter.go | 7 +++--- 45 files changed, 197 insertions(+), 133 deletions(-) diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index 241291673a3..fe8d9beb4e4 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -10,7 +10,6 @@ import ( "io" "github.com/azure/azure-dev/cli/azd/cmd/actions" - "github.com/azure/azure-dev/cli/azd/cmd/middleware" "github.com/azure/azure-dev/cli/azd/internal" "github.com/azure/azure-dev/cli/azd/pkg/account" "github.com/azure/azure-dev/cli/azd/pkg/environment" @@ -62,7 +61,7 @@ func envActions(root *actions.ActionDescriptor) *actions.ActionDescriptor { ActionResolver: newEnvListAction, OutputFormats: []output.Format{output.JsonFormat, output.TableFormat}, DefaultFormat: output.TableFormat, - }).UseMiddleware("query", middleware.NewQueryMiddleware) + }) group.Add("refresh", &actions.ActionDescriptorOptions{ Command: newEnvRefreshCmd(), diff --git a/cli/azd/cmd/root.go b/cli/azd/cmd/root.go index 7dc7bfc95cf..26267a911cb 100644 --- a/cli/azd/cmd/root.go +++ b/cli/azd/cmd/root.go @@ -337,7 +337,6 @@ func NewRootCmd( UseMiddlewareWhen("telemetry", middleware.NewTelemetryMiddleware, func(descriptor *actions.ActionDescriptor) bool { return !descriptor.Options.DisableTelemetry }) - // Register common dependencies for the IoC rootContainer if rootContainer == nil { rootContainer = ioc.NewNestedContainer(nil) diff --git a/cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap b/cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap index c9e531eda87..18185be8e80 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap @@ -18,9 +18,10 @@ Flags --use-device-code : When true, log in by using a device code instead of a browser. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap b/cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap index dbea8223056..fb044b8807e 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for logout. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-auth.snap b/cli/azd/cmd/testdata/TestUsage-azd-auth.snap index e6103d6f4bd..3f9c94fbc0e 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-auth.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-auth.snap @@ -13,9 +13,10 @@ Flags -h, --help : Gets help for auth. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd auth [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-get.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-get.snap index 9140907ba78..062fa0a0f90 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-get.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-get.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for get. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-list-alpha.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-list-alpha.snap index fe388c52716..67027099d38 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-list-alpha.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-list-alpha.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for list-alpha. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Displays a list of all available features in the alpha stage diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-reset.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-reset.snap index 6ad8eee995a..3044f1526c7 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-reset.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-reset.snap @@ -10,9 +10,10 @@ Flags -h, --help : Gets help for reset. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-set.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-set.snap index e0b76b40992..812b7820878 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-set.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-set.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for set. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-show.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-show.snap index 2fb607c6f14..21a22f976a0 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-show.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-show.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for show. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config-unset.snap b/cli/azd/cmd/testdata/TestUsage-azd-config-unset.snap index 500f1ac649e..3351edbbce8 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config-unset.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config-unset.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for unset. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-config.snap b/cli/azd/cmd/testdata/TestUsage-azd-config.snap index 26fc3cd2ecb..f719b63ec38 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-config.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-config.snap @@ -21,9 +21,10 @@ Flags -h, --help : Gets help for config. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd config [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-deploy.snap b/cli/azd/cmd/testdata/TestUsage-azd-deploy.snap index 2b67a55544c..eb6d1d21f60 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-deploy.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-deploy.snap @@ -16,9 +16,10 @@ Flags -h, --help : Gets help for deploy. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Deploy all services in the current project to Azure. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-down.snap b/cli/azd/cmd/testdata/TestUsage-azd-down.snap index a0195420330..62b44537371 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-down.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-down.snap @@ -12,9 +12,10 @@ Flags --purge : Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults). Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Delete all resources for an application. You will be prompted to confirm your decision. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-get-values.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-get-values.snap index 1ab3c5e4387..ae3a6cf75eb 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-get-values.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-get-values.snap @@ -10,9 +10,10 @@ Flags -h, --help : Gets help for get-values. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-list.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-list.snap index c0504ec4c2f..5c9821e7c47 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-list.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-list.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for list. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-new.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-new.snap index ac97334bd11..1223bbe8ae4 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-new.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-new.snap @@ -11,9 +11,10 @@ Flags --subscription string : Name or ID of an Azure subscription to use for the new environment Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-refresh.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-refresh.snap index 6eab5db918c..01258242e81 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-refresh.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-refresh.snap @@ -11,9 +11,10 @@ Flags --hint string : Hint to help identify the environment to refresh Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap index 3d2234b42de..ec922acd749 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for select. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-set.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-set.snap index 955650023ef..7874afda1a4 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-set.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-set.snap @@ -10,9 +10,10 @@ Flags -h, --help : Gets help for set. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env.snap b/cli/azd/cmd/testdata/TestUsage-azd-env.snap index 9949c306b0c..ad33b773f2c 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env.snap @@ -22,9 +22,10 @@ Flags -h, --help : Gets help for env. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd env [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-hooks-run.snap b/cli/azd/cmd/testdata/TestUsage-azd-hooks-run.snap index aff4cf2013d..e92d03e381d 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-hooks-run.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-hooks-run.snap @@ -12,9 +12,10 @@ Flags --service string : Only runs hooks for the specified service. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-hooks.snap b/cli/azd/cmd/testdata/TestUsage-azd-hooks.snap index cdd7cc09bc6..046f50b4b1a 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-hooks.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-hooks.snap @@ -12,9 +12,10 @@ Flags -h, --help : Gets help for hooks. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd hooks [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-init.snap b/cli/azd/cmd/testdata/TestUsage-azd-init.snap index 9fe4488b108..1019f3104e0 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-init.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-init.snap @@ -19,9 +19,10 @@ Flags -t, --template string : Initializes a new application from a template. You can use Full URI, /, or if it's part of the azure-samples organization. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Initialize a template to your current local directory from a GitHub repo. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-monitor.snap b/cli/azd/cmd/testdata/TestUsage-azd-monitor.snap index 231daf2591b..93f3404d129 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-monitor.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-monitor.snap @@ -13,9 +13,10 @@ Flags --overview : Open a browser to Application Insights Overview Dashboard. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Open Application Insights Live Metrics. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-package.snap b/cli/azd/cmd/testdata/TestUsage-azd-package.snap index b0c143d2556..1aef468d19d 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-package.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-package.snap @@ -16,9 +16,10 @@ Flags --output-path string : File or folder path where the generated packages will be saved. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Packages all services in the current project to Azure. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-pipeline-config.snap b/cli/azd/cmd/testdata/TestUsage-azd-pipeline-config.snap index 57d8485a8d3..825bd0d53af 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-pipeline-config.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-pipeline-config.snap @@ -21,9 +21,10 @@ Flags --remote-name string : The name of the git remote to configure the pipeline to run on. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Configure a deployment pipeline for 'app-test' environment diff --git a/cli/azd/cmd/testdata/TestUsage-azd-pipeline.snap b/cli/azd/cmd/testdata/TestUsage-azd-pipeline.snap index 3c0b864afb6..1ba8aef4fd8 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-pipeline.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-pipeline.snap @@ -16,9 +16,10 @@ Flags -h, --help : Gets help for pipeline. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd pipeline [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-provision.snap b/cli/azd/cmd/testdata/TestUsage-azd-provision.snap index 8c057e16609..35541c65a36 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-provision.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-provision.snap @@ -17,9 +17,10 @@ Flags --preview : Preview changes to Azure resources. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-restore.snap b/cli/azd/cmd/testdata/TestUsage-azd-restore.snap index 18b6ff1fd32..a366a3ff1c5 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-restore.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-restore.snap @@ -14,9 +14,10 @@ Flags -h, --help : Gets help for restore. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Examples Downloads and installs a specific application service dependency, Individual services are listed in your azure.yaml file. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-show.snap b/cli/azd/cmd/testdata/TestUsage-azd-show.snap index a01d41b9b3b..446d0f46409 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-show.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-show.snap @@ -10,9 +10,10 @@ Flags -h, --help : Gets help for show. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-list.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-list.snap index f6d7c2e4457..947fd65405d 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-list.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-list.snap @@ -11,9 +11,10 @@ Flags -s, --source string : Filters templates by source. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-show.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-show.snap index 2138d3a0de3..fa4b3e1eb1b 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-show.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-show.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for show. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-source-add.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-source-add.snap index 4f7d454535d..52bd8cebc78 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-source-add.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-source-add.snap @@ -12,9 +12,10 @@ Flags -t, --type string : Kind of the template source. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-source-list.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-source-list.snap index eefa16e0e49..87651ccff0e 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-source-list.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-source-list.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for list. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-source-remove.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-source-remove.snap index cbd57f3dc4b..e4ef65c9b6d 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-source-remove.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-source-remove.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for remove. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template-source.snap b/cli/azd/cmd/testdata/TestUsage-azd-template-source.snap index 31e981871e5..47a6c74fb76 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template-source.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template-source.snap @@ -17,9 +17,10 @@ Flags -h, --help : Gets help for source. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd template source [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-template.snap b/cli/azd/cmd/testdata/TestUsage-azd-template.snap index 52aa5015fe0..e35e0926f7d 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-template.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-template.snap @@ -18,9 +18,10 @@ Flags -h, --help : Gets help for template. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd template [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-up.snap b/cli/azd/cmd/testdata/TestUsage-azd-up.snap index 79dd47a615e..bfb5c7601a1 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-up.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-up.snap @@ -25,9 +25,10 @@ Flags -h, --help : Gets help for up. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd-version.snap b/cli/azd/cmd/testdata/TestUsage-azd-version.snap index e9a2fcaa6eb..807da49bf42 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-version.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-version.snap @@ -9,9 +9,10 @@ Flags -h, --help : Gets help for version. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. diff --git a/cli/azd/cmd/testdata/TestUsage-azd.snap b/cli/azd/cmd/testdata/TestUsage-azd.snap index b7d6761e339..77a4e955341 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd.snap @@ -30,11 +30,12 @@ Commands version : Print the version number of Azure Developer CLI. Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --docs : Opens the documentation for azd in your web browser. - -h, --help : Gets help for azd. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --docs : Opens the documentation for azd in your web browser. + -h, --help : Gets help for azd. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Use azd [command] --help to view examples and more information about a specific command. diff --git a/cli/azd/pkg/input/console_test.go b/cli/azd/pkg/input/console_test.go index 67d3d506a27..379a81748a4 100644 --- a/cli/azd/pkg/input/console_test.go +++ b/cli/azd/pkg/input/console_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/azure/azure-dev/cli/azd/internal" "github.com/azure/azure-dev/cli/azd/pkg/convert" "github.com/azure/azure-dev/cli/azd/pkg/output" "github.com/stretchr/testify/require" @@ -46,7 +47,17 @@ func TestAskerConsole_Spinner_NonTty(t *testing.T) { // We need to give it some time to paint. const cSleep = 50 * time.Millisecond - formatter, err := output.NewFormatter(string(output.NoneFormat)) + // Create and initialize GlobalCommandOptions + globalOptions := &internal.GlobalCommandOptions{ + Cwd: "/path/to/dir", + EnableDebugLogging: false, + NoPrompt: false, + EnableTelemetry: true, + GenerateStaticHelp: false, + Query: "", + } + + formatter, err := output.NewFormatter(string(output.NoneFormat), globalOptions) require.NoError(t, err) lines := &lineCapturer{} diff --git a/cli/azd/pkg/output/formatter.go b/cli/azd/pkg/output/formatter.go index cc14296dac1..41b26f04c84 100644 --- a/cli/azd/pkg/output/formatter.go +++ b/cli/azd/pkg/output/formatter.go @@ -6,6 +6,8 @@ package output import ( "fmt" "io" + + "github.com/azure/azure-dev/cli/azd/internal" ) type Format string @@ -22,10 +24,10 @@ type Formatter interface { Format(obj interface{}, writer io.Writer, opts interface{}) error } -func NewFormatter(format string) (Formatter, error) { +func NewFormatter(format string, globalOptions *internal.GlobalCommandOptions) (Formatter, error) { switch format { case string(JsonFormat): - return &JsonFormatter{}, nil + return NewJsonFormatter(globalOptions), nil case string(EnvVarsFormat): return &EnvVarsFormatter{}, nil case string(TableFormat): diff --git a/cli/azd/pkg/output/json.go b/cli/azd/pkg/output/json.go index 222aa2ba508..64fbb2f3608 100644 --- a/cli/azd/pkg/output/json.go +++ b/cli/azd/pkg/output/json.go @@ -1,6 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - package output import ( @@ -11,11 +8,18 @@ import ( "strings" "time" + "github.com/azure/azure-dev/cli/azd/internal" "github.com/azure/azure-dev/cli/azd/pkg/contracts" + "github.com/jmespath/go-jmespath" "github.com/mattn/go-colorable" ) type JsonFormatter struct { + globalOptions *internal.GlobalCommandOptions +} + +func NewJsonFormatter(globalOptions *internal.GlobalCommandOptions) *JsonFormatter { + return &JsonFormatter{globalOptions: globalOptions} } func (f *JsonFormatter) Kind() Format { @@ -23,6 +27,15 @@ func (f *JsonFormatter) Kind() Format { } func (f *JsonFormatter) Format(obj interface{}, writer io.Writer, _ interface{}) error { + if f.globalOptions != nil && f.globalOptions.Query != "" { + // Apply the JMESPath query to the obj + filteredObj, err := jmespath.Search(f.globalOptions.Query, obj) + if err != nil { + return fmt.Errorf("applying JMESPath query: %w", err) + } + obj = filteredObj + } + b, err := json.MarshalIndent(obj, "", " ") if err != nil { return err @@ -43,8 +56,8 @@ func (f *JsonFormatter) Format(obj interface{}, writer io.Writer, _ interface{}) var _ Formatter = (*JsonFormatter)(nil) -// jsonObjectForMessage creates a json object representing a message. Any ANSI control sequences from the message are -// removed. A trailing newline is added to the message. +// jsonObjectForMessage creates a json object representing a message. +// Any ANSI control sequences from the message are removed. A trailing newline is added to the message. func EventForMessage(message string) contracts.EventEnvelope { // Strip any ANSI colors for the message. var buf bytes.Buffer diff --git a/cli/azd/pkg/output/parameter.go b/cli/azd/pkg/output/parameter.go index d6998b07899..80c5eeaea01 100644 --- a/cli/azd/pkg/output/parameter.go +++ b/cli/azd/pkg/output/parameter.go @@ -7,6 +7,7 @@ import ( "fmt" "strings" + "github.com/azure/azure-dev/cli/azd/internal" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -37,7 +38,7 @@ func AddOutputParam(cmd *cobra.Command, supportedFormats []Format, defaultFormat return cmd } -func GetCommandFormatter(cmd *cobra.Command) (Formatter, error) { +func GetCommandFormatter(cmd *cobra.Command, globalOptions *internal.GlobalCommandOptions) (Formatter, error) { // If the command does not specify any output params just return nil Formatter pointer outputVal, err := cmd.Flags().GetString(outputFlagName) if err != nil { @@ -48,7 +49,7 @@ func GetCommandFormatter(cmd *cobra.Command) (Formatter, error) { f := cmd.Flags().Lookup(outputFlagName) supportedFormatters, hasFormatters := f.Annotations[supportedFormatterAnnotation] if !hasFormatters { - return NewFormatter(desiredFormatter) + return NewFormatter(desiredFormatter, globalOptions) } supported := false @@ -62,5 +63,5 @@ func GetCommandFormatter(cmd *cobra.Command) (Formatter, error) { return nil, fmt.Errorf("unsupported format '%s'", desiredFormatter) } - return NewFormatter(desiredFormatter) + return NewFormatter(desiredFormatter, globalOptions) } From 365d04dd8a31830ce7a807b20230e5fcc9846c1e Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:43:18 +0000 Subject: [PATCH 4/9] update cspell --- .vscode/cspell.global.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/cspell.global.yaml b/.vscode/cspell.global.yaml index 94465ad0248..651166e18f1 100644 --- a/.vscode/cspell.global.yaml +++ b/.vscode/cspell.global.yaml @@ -80,6 +80,7 @@ ignoreWords: - infradelete - inputhelper - ippre + - jmespath - JOBOBJECT - kubernetes - kusto From 33c98ec81050704c7f49926ac0d46f370b65feae Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Tue, 9 Jul 2024 20:20:28 +0000 Subject: [PATCH 5/9] Add set-shell-context --- cli/azd/cmd/env.go | 78 +++++++++++++++++++ .../TestUsage-azd-env-set-shell-context.snap | 20 +++++ cli/azd/cmd/testdata/TestUsage-azd-env.snap | 13 ++-- 3 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 cli/azd/cmd/testdata/TestUsage-azd-env-set-shell-context.snap diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index fe8d9beb4e4..efa67ed8526 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -79,6 +79,11 @@ func envActions(root *actions.ActionDescriptor) *actions.ActionDescriptor { DefaultFormat: output.EnvVarsFormat, }) + group.Add("set-shell-context", &actions.ActionDescriptorOptions{ + Command: newEnvSetShellContextCmd(), + FlagsResolver: newEnvSetShellContextFlags, + ActionResolver: newEnvSetShellContextAction, + }) return group } @@ -607,3 +612,76 @@ func getCmdEnvHelpDescription(*cobra.Command) string { output.WithLinkFormat(".azure//.env"))), }) } + +func newEnvSetShellContextCmd() *cobra.Command { + return &cobra.Command{ + Use: "set-shell-context", + Short: "Set the current environment variables to the shell context.", + Args: cobra.NoArgs, + } +} + +func newEnvSetShellContextFlags(cmd *cobra.Command, global *internal.GlobalCommandOptions) *envSetShellContextFlags { + flags := &envSetShellContextFlags{} + flags.Bind(cmd.Flags(), global) + + return flags +} + +type envSetShellContextFlags struct { + internal.EnvFlag + global *internal.GlobalCommandOptions +} + +func (f *envSetShellContextFlags) Bind(local *pflag.FlagSet, global *internal.GlobalCommandOptions) { + f.EnvFlag.Bind(local, global) + f.global = global +} + +type envSetShellContextAction struct { + azdCtx *azdcontext.AzdContext + envManager environment.Manager + console input.Console + flags *envSetShellContextFlags +} + +func newEnvSetShellContextAction( + azdCtx *azdcontext.AzdContext, + envManager environment.Manager, + console input.Console, + flags *envSetShellContextFlags, +) actions.Action { + return &envSetShellContextAction{ + azdCtx: azdCtx, + envManager: envManager, + console: console, + flags: flags, + } +} + +func (e *envSetShellContextAction) Run(ctx context.Context) (*actions.ActionResult, error) { + envName, err := e.azdCtx.GetDefaultEnvironmentName() + if err != nil { + return nil, err + } + if envName == "" { + return nil, fmt.Errorf("no default environment set") + } + + env, err := e.envManager.Get(ctx, envName) + if errors.Is(err, environment.ErrNotFound) { + return nil, fmt.Errorf( + "environment '%s' does not exist. You can create it with 'azd env new %s'", + envName, envName, + ) + } else if err != nil { + return nil, fmt.Errorf("ensuring environment exists: %w", err) + } + + envVars := env.Dotenv() + for key, value := range envVars { + fmt.Printf("export %s=%q\n", key, value) + } + + return nil, nil +} diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-set-shell-context.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-set-shell-context.snap new file mode 100644 index 00000000000..d08e8c45434 --- /dev/null +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-set-shell-context.snap @@ -0,0 +1,20 @@ + +Set the current environment variables to the shell context. + +Usage + azd env set-shell-context [flags] + +Flags + --docs : Opens the documentation for azd env set-shell-context in your web browser. + -e, --environment string : The name of the environment to use. + -h, --help : Gets help for set-shell-context. + +Global Flags + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results + +Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. + + diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env.snap b/cli/azd/cmd/testdata/TestUsage-azd-env.snap index ad33b773f2c..d0d40f455fa 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env.snap @@ -10,12 +10,13 @@ Usage azd env [command] Available Commands - get-values : Get all environment values. - list : List environments. - new : Create a new environment and set it as the default. - refresh : Refresh environment settings by using information from a previous infrastructure provision. - select : Set the default environment. - set : Manage your environment settings. + get-values : Get all environment values. + list : List environments. + new : Create a new environment and set it as the default. + refresh : Refresh environment settings by using information from a previous infrastructure provision. + select : Set the default environment. + set : Manage your environment settings. + set-shell-context : Set the current environment variables to the shell context. Flags --docs : Opens the documentation for azd env in your web browser. From a24727023f8cf780c0bb363762cd60fd3785dbc9 Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Tue, 9 Jul 2024 20:38:19 +0000 Subject: [PATCH 6/9] Chnage to -o export --- cli/azd/cmd/env.go | 80 +-------------------- cli/azd/cmd/testdata/TestUsage-azd-env.snap | 13 ++-- cli/azd/pkg/output/export.go | 37 ++++++++++ cli/azd/pkg/output/formatter.go | 3 + 4 files changed, 47 insertions(+), 86 deletions(-) create mode 100644 cli/azd/pkg/output/export.go diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index efa67ed8526..9ff14381bda 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -75,15 +75,10 @@ func envActions(root *actions.ActionDescriptor) *actions.ActionDescriptor { Command: newEnvGetValuesCmd(), FlagsResolver: newEnvGetValuesFlags, ActionResolver: newEnvGetValuesAction, - OutputFormats: []output.Format{output.JsonFormat, output.EnvVarsFormat}, + OutputFormats: []output.Format{output.JsonFormat, output.EnvVarsFormat, output.ExportFormat}, DefaultFormat: output.EnvVarsFormat, }) - group.Add("set-shell-context", &actions.ActionDescriptorOptions{ - Command: newEnvSetShellContextCmd(), - FlagsResolver: newEnvSetShellContextFlags, - ActionResolver: newEnvSetShellContextAction, - }) return group } @@ -612,76 +607,3 @@ func getCmdEnvHelpDescription(*cobra.Command) string { output.WithLinkFormat(".azure//.env"))), }) } - -func newEnvSetShellContextCmd() *cobra.Command { - return &cobra.Command{ - Use: "set-shell-context", - Short: "Set the current environment variables to the shell context.", - Args: cobra.NoArgs, - } -} - -func newEnvSetShellContextFlags(cmd *cobra.Command, global *internal.GlobalCommandOptions) *envSetShellContextFlags { - flags := &envSetShellContextFlags{} - flags.Bind(cmd.Flags(), global) - - return flags -} - -type envSetShellContextFlags struct { - internal.EnvFlag - global *internal.GlobalCommandOptions -} - -func (f *envSetShellContextFlags) Bind(local *pflag.FlagSet, global *internal.GlobalCommandOptions) { - f.EnvFlag.Bind(local, global) - f.global = global -} - -type envSetShellContextAction struct { - azdCtx *azdcontext.AzdContext - envManager environment.Manager - console input.Console - flags *envSetShellContextFlags -} - -func newEnvSetShellContextAction( - azdCtx *azdcontext.AzdContext, - envManager environment.Manager, - console input.Console, - flags *envSetShellContextFlags, -) actions.Action { - return &envSetShellContextAction{ - azdCtx: azdCtx, - envManager: envManager, - console: console, - flags: flags, - } -} - -func (e *envSetShellContextAction) Run(ctx context.Context) (*actions.ActionResult, error) { - envName, err := e.azdCtx.GetDefaultEnvironmentName() - if err != nil { - return nil, err - } - if envName == "" { - return nil, fmt.Errorf("no default environment set") - } - - env, err := e.envManager.Get(ctx, envName) - if errors.Is(err, environment.ErrNotFound) { - return nil, fmt.Errorf( - "environment '%s' does not exist. You can create it with 'azd env new %s'", - envName, envName, - ) - } else if err != nil { - return nil, fmt.Errorf("ensuring environment exists: %w", err) - } - - envVars := env.Dotenv() - for key, value := range envVars { - fmt.Printf("export %s=%q\n", key, value) - } - - return nil, nil -} diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env.snap b/cli/azd/cmd/testdata/TestUsage-azd-env.snap index d0d40f455fa..ad33b773f2c 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env.snap @@ -10,13 +10,12 @@ Usage azd env [command] Available Commands - get-values : Get all environment values. - list : List environments. - new : Create a new environment and set it as the default. - refresh : Refresh environment settings by using information from a previous infrastructure provision. - select : Set the default environment. - set : Manage your environment settings. - set-shell-context : Set the current environment variables to the shell context. + get-values : Get all environment values. + list : List environments. + new : Create a new environment and set it as the default. + refresh : Refresh environment settings by using information from a previous infrastructure provision. + select : Set the default environment. + set : Manage your environment settings. Flags --docs : Opens the documentation for azd env in your web browser. diff --git a/cli/azd/pkg/output/export.go b/cli/azd/pkg/output/export.go new file mode 100644 index 00000000000..edb619fcb55 --- /dev/null +++ b/cli/azd/pkg/output/export.go @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package output + +import ( + "fmt" + "io" +) + +type ExportFormatter struct { +} + +func (f *ExportFormatter) Kind() Format { + return ExportFormat +} + +func (f *ExportFormatter) Format(obj interface{}, writer io.Writer, _ interface{}) error { + values, ok := obj.(map[string]string) + if !ok { + return fmt.Errorf("ExportFormatter can only format objects of type map[string]string") + } + + var content string + for key, value := range values { + content += fmt.Sprintf("export %s=%s\n", key, value) + } + + _, err := writer.Write([]byte(content)) + if err != nil { + return fmt.Errorf("could not write content: %w", err) + } + + return nil +} + +var _ Formatter = (*ExportFormatter)(nil) diff --git a/cli/azd/pkg/output/formatter.go b/cli/azd/pkg/output/formatter.go index 41b26f04c84..c5cb863f4e6 100644 --- a/cli/azd/pkg/output/formatter.go +++ b/cli/azd/pkg/output/formatter.go @@ -14,6 +14,7 @@ type Format string const ( EnvVarsFormat Format = "dotenv" + ExportFormat Format = "export" JsonFormat Format = "json" TableFormat Format = "table" NoneFormat Format = "none" @@ -30,6 +31,8 @@ func NewFormatter(format string, globalOptions *internal.GlobalCommandOptions) ( return NewJsonFormatter(globalOptions), nil case string(EnvVarsFormat): return &EnvVarsFormatter{}, nil + case string(ExportFormat): + return &ExportFormatter{}, nil case string(TableFormat): return &TableFormatter{}, nil case string(NoneFormat): From cea21780688def25217ab9b4bba3cbd97262a1e6 Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:34:41 +0000 Subject: [PATCH 7/9] Refactor JSON formatter to handle nil filtered object --- cli/azd/pkg/output/json.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/azd/pkg/output/json.go b/cli/azd/pkg/output/json.go index 64fbb2f3608..82592af1413 100644 --- a/cli/azd/pkg/output/json.go +++ b/cli/azd/pkg/output/json.go @@ -33,6 +33,9 @@ func (f *JsonFormatter) Format(obj interface{}, writer io.Writer, _ interface{}) if err != nil { return fmt.Errorf("applying JMESPath query: %w", err) } + if filteredObj == nil { + filteredObj = "" + } obj = filteredObj } From be05d8a157455c17e46408069dfc30001d42e828 Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:23:05 +0000 Subject: [PATCH 8/9] Update usage --- cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap index 5bc02856194..2d2c5bdf790 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap @@ -10,9 +10,10 @@ Flags -h, --help : Gets help for get-value. Global Flags - -C, --cwd string : Sets the current working directory. - --debug : Enables debugging and diagnostics logging. - --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -C, --cwd string : Sets the current working directory. + --debug : Enables debugging and diagnostics logging. + --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. + -q, --query string : Run jmespath query on results Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats. From d47b1c263950ad411bbc266cfd9b3e0ea127d44e Mon Sep 17 00:00:00 2001 From: Jon Gallant <2163001+jongio@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:28:39 +0000 Subject: [PATCH 9/9] refactor: Add shell detection and formatting for export values --- cli/azd/pkg/output/export.go | 75 ++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/cli/azd/pkg/output/export.go b/cli/azd/pkg/output/export.go index edb619fcb55..041331705b3 100644 --- a/cli/azd/pkg/output/export.go +++ b/cli/azd/pkg/output/export.go @@ -6,27 +6,94 @@ package output import ( "fmt" "io" + "os" + "runtime" + "strings" ) -type ExportFormatter struct { -} +type ExportFormatter struct{} + +type ShellType string + +const ( + BashShell ShellType = "bash" + ZshShell ShellType = "zsh" + FishShell ShellType = "fish" + PwshShell ShellType = "pwsh" + CmdShell ShellType = "cmd" + DefaultShell ShellType = "default" +) func (f *ExportFormatter) Kind() Format { return ExportFormat } +func detectShell() (ShellType, error) { + // Check environment variable SHELL for Unix-like systems + shell := os.Getenv("SHELL") + if shell == "" { + // Check environment variable ComSpec for Windows systems + shell = os.Getenv("ComSpec") + if shell != "" { + if strings.Contains(strings.ToLower(shell), "cmd") { + return CmdShell, nil + } + } + // Check environment variable PSModulePath for PowerShell + if os.Getenv("PSModulePath") != "" { + return PwshShell, nil + } + if runtime.GOOS == "windows" { + return CmdShell, nil + } else { + return DefaultShell, fmt.Errorf("could not detect shell") + } + } + + if strings.Contains(shell, "bash") { + return BashShell, nil + } else if strings.Contains(shell, "zsh") { + return ZshShell, nil + } else if strings.Contains(shell, "fish") { + return FishShell, nil + } else { + return DefaultShell, fmt.Errorf("unsupported shell: %s", shell) + } +} + func (f *ExportFormatter) Format(obj interface{}, writer io.Writer, _ interface{}) error { values, ok := obj.(map[string]string) if !ok { return fmt.Errorf("ExportFormatter can only format objects of type map[string]string") } + shell, err := detectShell() + if err != nil && shell == DefaultShell { + // Fallback to default shell based on OS + if runtime.GOOS == "windows" { + shell = CmdShell + } else { + shell = BashShell + } + } + var content string for key, value := range values { - content += fmt.Sprintf("export %s=%s\n", key, value) + switch shell { + case BashShell, ZshShell: + content += fmt.Sprintf("export %s=\"%s\"\n", key, value) + case FishShell: + content += fmt.Sprintf("set -x %s \"%s\"\n", key, value) + case PwshShell: + content += fmt.Sprintf("$Env:%s = \"%s\"\n", key, value) + case CmdShell: + content += fmt.Sprintf("set %s=%s\n", key, value) + default: + return fmt.Errorf("unsupported shell type: %s", shell) + } } - _, err := writer.Write([]byte(content)) + _, err = writer.Write([]byte(content)) if err != nil { return fmt.Errorf("could not write content: %w", err) }