Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: azd template sources #2573

Merged
merged 24 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/azd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features Added

- [[2573]](https://github.com/Azure/azure-dev/pull/2573) Adds support for custom template sources

### Breaking Changes

### Bugs Fixed
Expand All @@ -17,7 +19,6 @@
- [[2550]](https://github.com/Azure/azure-dev/pull/2550) Add `--preview` to `azd provision` to get the changes.
- [[2521]](https://github.com/Azure/azure-dev/pull/2521) Support `--principal-id` param for azd pipeline config to reuse existing service principal.
- [[2455]](https://github.com/Azure/azure-dev/pull/2455) Adds optional support for text templates in AKS k8s manifests.
-

### Bugs Fixed

Expand Down
62 changes: 59 additions & 3 deletions cli/azd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/config"
"github.com/azure/azure-dev/cli/azd/pkg/input"
"github.com/azure/azure-dev/cli/azd/pkg/output"
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -140,6 +141,7 @@ $ azd config set defaults.location eastus`,
Long: `Resets all configuration in ` + userConfigPath + ` to the default.`,
},
ActionResolver: newConfigResetAction,
FlagsResolver: newConfigResetFlags,
})

group.Add("list-alpha", &actions.ActionDescriptorOptions{
Expand Down Expand Up @@ -304,22 +306,76 @@ func (a *configUnsetAction) Run(ctx context.Context) (*actions.ActionResult, err

// azd config reset

type configResetActionFlags struct {
force bool
}

func newConfigResetFlags(cmd *cobra.Command) *configResetActionFlags {
flags := &configResetActionFlags{}
cmd.Flags().BoolVarP(&flags.force, "force", "f", false, "Force reset without confirmation.")

return flags
}

type configResetAction struct {
console input.Console
configManager config.UserConfigManager
flags *configResetActionFlags
args []string
}

func newConfigResetAction(configManager config.UserConfigManager, args []string) actions.Action {
func newConfigResetAction(
console input.Console,
configManager config.UserConfigManager,
flags *configResetActionFlags, args []string,
) actions.Action {
return &configResetAction{
console: console,
configManager: configManager,
flags: flags,
args: args,
}
}

// Executes the `azd config reset` action
func (a *configResetAction) Run(ctx context.Context) (*actions.ActionResult, error) {
emptyConfig := config.NewEmptyConfig()
return nil, a.configManager.Save(emptyConfig)
a.console.MessageUxItem(ctx, &ux.MessageTitle{
Title: "Reset configuration (azd config reset)",
})

spinnerMessage := "Resetting azd configuration"
a.console.ShowSpinner(ctx, spinnerMessage, input.Step)

if !a.flags.force {
// nolint:lll
warningMessage := "WARNING: Resetting azd configuration will remove all stored values including defaults, feature flags and custom template sources.\n\n"
a.console.Message(ctx, output.WithWarningFormat(warningMessage))

confirm, err := a.console.Confirm(ctx, input.ConsoleOptions{
Message: "Continue with reset?",
DefaultValue: false,
})

if !confirm || err != nil {
a.console.StopSpinner(ctx, spinnerMessage, input.StepSkipped)
if err != nil {
return nil, fmt.Errorf("user cancelled reset confirmation, %w", err)
}
return nil, nil
}
}

err := a.configManager.Save(config.NewEmptyConfig())
a.console.StopSpinner(ctx, spinnerMessage, input.GetStepResultFormat(err))
if err != nil {
return nil, err
}

return &actions.ActionResult{
Message: &actions.ResultMessage{
Header: "Configuration reset",
},
}, nil
}

func getCmdConfigHelpDescription(*cobra.Command) string {
Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
container.RegisterSingleton(alpha.NewFeaturesManager)
container.RegisterSingleton(config.NewManager)
container.RegisterSingleton(templates.NewTemplateManager)
container.RegisterSingleton(templates.NewSourceManager)
container.RegisterSingleton(auth.NewManager)
container.RegisterSingleton(azcli.NewUserProfileService)
container.RegisterSingleton(account.NewSubscriptionsService)
Expand Down
13 changes: 9 additions & 4 deletions cli/azd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,23 @@ type initAction struct {
gitCli git.GitCli
flags *initFlags
repoInitializer *repository.Initializer
templateManager *templates.TemplateManager
}

func newInitAction(
cmdRun exec.CommandRunner,
console input.Console,
gitCli git.GitCli,
flags *initFlags,
repoInitializer *repository.Initializer) actions.Action {
repoInitializer *repository.Initializer,
templateManager *templates.TemplateManager) actions.Action {
return &initAction{
console: console,
cmdRun: cmdRun,
gitCli: gitCli,
flags: flags,
repoInitializer: repoInitializer,
templateManager: templateManager,
}
}

Expand Down Expand Up @@ -144,12 +147,14 @@ func (i *initAction) Run(ctx context.Context) (*actions.ActionResult, error) {
}

if i.flags.templatePath == "" {
template, err := templates.PromptTemplate(ctx, "Select a project template:", i.console)
i.flags.templatePath = template.RepositoryPath

template, err := templates.PromptTemplate(ctx, "Select a project template:", i.templateManager, i.console)
wbreza marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

if template != nil {
i.flags.templatePath = template.RepositoryPath
}
}
}

Expand Down
Loading