Skip to content

Commit

Permalink
Update src to use 125 max line long for easier GitHub reviews (#880)
Browse files Browse the repository at this point in the history
* auto format

* comments

* semi-manual

* cspell

* cspell again
  • Loading branch information
vhvb1989 committed Oct 12, 2022
1 parent 467421a commit c53a984
Show file tree
Hide file tree
Showing 113 changed files with 2,242 additions and 533 deletions.
6 changes: 5 additions & 1 deletion cli/azd/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ linters:
enable:
- errorlint
- gofmt
- lll
linters-settings:
errorlint:
errorf: true
asserts: true
comparison: true
comparison: true
lll:
# GitHub recommended for code review
line-length: 125
16 changes: 14 additions & 2 deletions cli/azd/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func deployCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
"deploy",
"Deploy the application's code to Azure.",
&commands.BuildOptions{
//nolint:lll
Long: `Deploy the application's code to Azure.
When no ` + output.WithBackticks("--service") + ` value is specified, all services in the ` + output.WithBackticks("azure.yaml") + ` file (found in the root of your project) are deployed.
Expand Down Expand Up @@ -62,7 +63,13 @@ func (d *deployAction) SetupFlags(
persis *pflag.FlagSet,
local *pflag.FlagSet,
) {
local.StringVar(&d.serviceName, "service", "", "Deploys a specific service (when the string is unspecified, all services that are listed in the "+azdcontext.ProjectFileName+" file are deployed).")
local.StringVar(
&d.serviceName,
"service",
"",
"Deploys a specific service (when the string is unspecified, "+
"all services that are listed in the "+azdcontext.ProjectFileName+" file are deployed).",
)
}

func (d *deployAction) Run(ctx context.Context, cmd *cobra.Command, args []string, azdCtx *azdcontext.AzdContext) error {
Expand Down Expand Up @@ -185,7 +192,12 @@ func (d *deployAction) Run(ctx context.Context, cmd *cobra.Command, args []strin
return nil
}

func reportServiceDeploymentResultInteractive(ctx context.Context, console input.Console, svc *project.Service, sdr *project.ServiceDeploymentResult) {
func reportServiceDeploymentResultInteractive(
ctx context.Context,
console input.Console,
svc *project.Service,
sdr *project.ServiceDeploymentResult,
) {
var builder strings.Builder

builder.WriteString(fmt.Sprintf("Deployed service %s\n", output.WithHighLightFormat(svc.Config.Name)))
Expand Down
22 changes: 19 additions & 3 deletions cli/azd/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func envCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
root := &cobra.Command{
Use: "env",
Short: "Manage environments.",
//nolint:lll
Long: `Manage environments.
With this command group, you can create a new environment or get, set, and list your application environments. An application can have multiple environments (for example, dev, test, prod), each with a different configuration (that is, connectivity information) for accessing Azure resources.
Expand Down Expand Up @@ -70,7 +71,12 @@ func envSetCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
}

//lint:ignore SA4006 // We want ctx overridden here for future changes
env, ctx, err := loadOrInitEnvironment(ctx, &rootOptions.EnvironmentName, azdCtx, console) //nolint:ineffassign,staticcheck
env, ctx, err := loadOrInitEnvironment( //nolint:ineffassign,staticcheck
ctx,
&rootOptions.EnvironmentName,
azdCtx,
console,
)
if err != nil {
return fmt.Errorf("loading environment: %w", err)
}
Expand Down Expand Up @@ -190,7 +196,12 @@ type envNewAction struct {
}

func (en *envNewAction) SetupFlags(persis *pflag.FlagSet, local *pflag.FlagSet) {
local.StringVar(&en.subscription, "subscription", "", "Name or ID of an Azure subscription to use for the new environment")
local.StringVar(
&en.subscription,
"subscription",
"",
"Name or ID of an Azure subscription to use for the new environment",
)
local.StringVarP(&en.location, "location", "l", "", "Azure location for the new environment")
}

Expand Down Expand Up @@ -306,7 +317,12 @@ func envGetValuesCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command
writer := output.GetWriter(ctx)

//lint:ignore SA4006 // We want ctx overridden here for future changes
env, ctx, err := loadOrInitEnvironment(ctx, &rootOptions.EnvironmentName, azdCtx, console) //nolint:ineffassign,staticcheck
env, ctx, err := loadOrInitEnvironment( //nolint:ineffassign,staticcheck
ctx,
&rootOptions.EnvironmentName,
azdCtx,
console,
)
if err != nil {
return err
}
Expand Down
31 changes: 25 additions & 6 deletions cli/azd/cmd/infra_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func (ica *infraCreateAction) SetupFlags(persis, local *pflag.FlagSet) {
local.BoolVar(&ica.noProgress, "no-progress", false, "Suppresses progress information.")
}

func (ica *infraCreateAction) Run(ctx context.Context, cmd *cobra.Command, args []string, azdCtx *azdcontext.AzdContext) error {
func (ica *infraCreateAction) Run(
ctx context.Context,
cmd *cobra.Command,
args []string,
azdCtx *azdcontext.AzdContext,
) error {
azCli := azcli.GetAzCli(ctx)
console := input.GetConsole(ctx)

Expand Down Expand Up @@ -100,19 +105,28 @@ func (ica *infraCreateAction) Run(ctx context.Context, cmd *cobra.Command, args
if formatter.Kind() == output.JsonFormat {
stateResult, err := infraManager.State(ctx, provisioningScope)
if err != nil {
return fmt.Errorf("deployment failed and the deployment result is unavailable: %w", multierr.Combine(err, err))
return fmt.Errorf(
"deployment failed and the deployment result is unavailable: %w",
multierr.Combine(err, err),
)
}

if err := formatter.Format(contracts.NewEnvRefreshResultFromProvisioningState(stateResult.State), writer, nil); err != nil {
return fmt.Errorf("deployment failed and the deployment result could not be displayed: %w", multierr.Combine(err, err))
if err := formatter.Format(
contracts.NewEnvRefreshResultFromProvisioningState(stateResult.State), writer, nil); err != nil {
return fmt.Errorf(
"deployment failed and the deployment result could not be displayed: %w",
multierr.Combine(err, err),
)
}
}

return fmt.Errorf("deployment failed: %w", err)
}

for _, svc := range prj.Services {
if err := svc.RaiseEvent(ctx, project.Deployed, map[string]any{"bicepOutput": deployResult.Deployment.Outputs}); err != nil {
if err := svc.RaiseEvent(
ctx, project.Deployed,
map[string]any{"bicepOutput": deployResult.Deployment.Outputs}); err != nil {
return err
}
}
Expand All @@ -125,7 +139,12 @@ func (ica *infraCreateAction) Run(ctx context.Context, cmd *cobra.Command, args
return nil
}

func (ica *infraCreateAction) displayResourceGroupCreatedMessage(ctx context.Context, console input.Console, subscriptionId string, resourceGroup string) {
func (ica *infraCreateAction) displayResourceGroupCreatedMessage(
ctx context.Context,
console input.Console,
subscriptionId string,
resourceGroup string,
) {
resourceGroupCreatedMessage := resourceGroupCreatedMessage(ctx, subscriptionId, resourceGroup)
if ica.finalOutputRedirect != nil {
*ica.finalOutputRedirect = append(*ica.finalOutputRedirect, resourceGroupCreatedMessage)
Expand Down
15 changes: 13 additions & 2 deletions cli/azd/cmd/infra_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ func (a *infraDeleteAction) SetupFlags(
local *pflag.FlagSet,
) {
local.BoolVar(&a.forceDelete, "force", false, "Does not require confirmation before it deletes resources.")
local.BoolVar(&a.purgeDelete, "purge", false, "Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).")
local.BoolVar(
&a.purgeDelete,
"purge",
false,
"Does not require confirmation before it permanently deletes resources that are"+
" soft-deleted by default (for example, key vaults).",
)
}

func (a *infraDeleteAction) Run(ctx context.Context, cmd *cobra.Command, args []string, azdCtx *azdcontext.AzdContext) error {
func (a *infraDeleteAction) Run(
ctx context.Context,
cmd *cobra.Command,
args []string,
azdCtx *azdcontext.AzdContext,
) error {
azCli := azcli.GetAzCli(ctx)
console := input.GetConsole(ctx)

Expand Down
34 changes: 29 additions & 5 deletions cli/azd/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func initCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
"init",
"Initialize a new application.",
&commands.BuildOptions{
//nolint:lll
Long: `Initialize a new application.
When no template is supplied, you can optionally select an Azure Developer CLI template for cloning. Otherwise, ` + output.WithBackticks("azd init") + ` initializes the current directory and creates resources so that your project is compatible with Azure Developer CLI.
Expand All @@ -62,9 +63,21 @@ func (i *initAction) SetupFlags(
persis *pflag.FlagSet,
local *pflag.FlagSet,
) {
local.StringVarP(&i.template.Name, "template", "t", "", "The template to use when you initialize the project. You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.")
local.StringVarP(
&i.template.Name,
"template",
"t",
"",
"The template to use when you initialize the project. "+
"You can use Full URI, <owner>/<repository>, or <repository> if it's part of the azure-samples organization.",
)
local.StringVarP(&i.templateBranch, "branch", "b", "", "The template branch to initialize from.")
local.StringVar(&i.subscription, "subscription", "", "Name or ID of an Azure subscription to use for the new environment")
local.StringVar(
&i.subscription,
"subscription",
"",
"Name or ID of an Azure subscription to use for the new environment",
)
local.StringVarP(&i.location, "location", "l", "", "Azure location for the new environment")
}

Expand Down Expand Up @@ -155,7 +168,11 @@ func (i *initAction) Run(ctx context.Context, cmd *cobra.Command, args []string,
return fmt.Errorf("fetching template: %w", err)
}

log.Printf("template init, checking for duplicates. source: %s target: %s", templateStagingDir, azdCtx.ProjectDirectory())
log.Printf(
"template init, checking for duplicates. source: %s target: %s",
templateStagingDir,
azdCtx.ProjectDirectory(),
)

// If there are any existing files in the destination that would be overwritten by files from the
// template, have the user confirm they would like to overwrite these files. This is a more relaxed
Expand Down Expand Up @@ -234,13 +251,20 @@ func (i *initAction) Run(ctx context.Context, cmd *cobra.Command, args []string,
}

//create .azure when running azd init
err = os.MkdirAll(filepath.Join(azdCtx.ProjectDirectory(), azdcontext.EnvironmentDirectoryName), osutil.PermissionDirectory)
err = os.MkdirAll(
filepath.Join(azdCtx.ProjectDirectory(), azdcontext.EnvironmentDirectoryName),
osutil.PermissionDirectory,
)
if err != nil {
return fmt.Errorf("failed to create a directory: %w", err)
}

//create .gitignore or open existing .gitignore file, and contains .azure
gitignoreFile, err := os.OpenFile(filepath.Join(azdCtx.ProjectDirectory(), ".gitignore"), os.O_APPEND|os.O_RDWR|os.O_CREATE, osutil.PermissionFile)
gitignoreFile, err := os.OpenFile(
filepath.Join(azdCtx.ProjectDirectory(), ".gitignore"),
os.O_APPEND|os.O_RDWR|os.O_CREATE,
osutil.PermissionFile,
)
if err != nil {
return fmt.Errorf("fail to create or open .gitignore: %w", err)
}
Expand Down
13 changes: 10 additions & 3 deletions cli/azd/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (la *loginAction) Run(ctx context.Context, cmd *cobra.Command, args []strin

var res contracts.LoginResult

if token, err := azCli.GetAccessToken(ctx); errors.Is(err, azcli.ErrAzCliNotLoggedIn) || errors.Is(err, azcli.ErrAzCliRefreshTokenExpired) {
if token, err := azCli.GetAccessToken(ctx); errors.Is(err, azcli.ErrAzCliNotLoggedIn) ||
errors.Is(err, azcli.ErrAzCliRefreshTokenExpired) {
res.Status = contracts.LoginStatusUnauthenticated
} else if err != nil {
return fmt.Errorf("checking auth status: %w", err)
Expand All @@ -87,7 +88,12 @@ func (la *loginAction) Run(ctx context.Context, cmd *cobra.Command, args []strin

func (la *loginAction) SetupFlags(persistent *pflag.FlagSet, local *pflag.FlagSet) {
local.BoolVar(&la.onlyCheckStatus, "check-status", false, "Checks the log-in status instead of logging in.")
local.BoolVar(&la.useDeviceCode, "use-device-code", false, "When true, log in by using a device code instead of a browser.")
local.BoolVar(
&la.useDeviceCode,
"use-device-code",
false,
"When true, log in by using a device code instead of a browser.",
)
}

// ensureLoggedIn checks to see if the user is currently logged in. If not, the equivalent of `az login` is run.
Expand Down Expand Up @@ -119,7 +125,8 @@ func runLogin(ctx context.Context, forceDeviceCode bool) error {
)

azCli := azcli.GetAzCli(ctx)
useDeviceCode := forceDeviceCode || os.Getenv(CodespacesEnvVarName) == "true" || os.Getenv(RemoteContainersEnvVarName) == "true"
useDeviceCode := forceDeviceCode || os.Getenv(CodespacesEnvVarName) == "true" ||
os.Getenv(RemoteContainersEnvVarName) == "true"

return azCli.Login(ctx, useDeviceCode, os.Stdout)
}
7 changes: 6 additions & 1 deletion cli/azd/cmd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func (m *monitorAction) SetupFlags(
persis *pflag.FlagSet,
local *pflag.FlagSet,
) {
persis.BoolVar(&m.monitorLive, "live", false, "Open a browser to Application Insights Live Metrics. Live Metrics is currently not supported for Python applications.")
persis.BoolVar(
&m.monitorLive,
"live",
false,
"Open a browser to Application Insights Live Metrics. Live Metrics is currently not supported for Python applications.",
)
persis.BoolVar(&m.monitorLogs, "logs", false, "Open a browser to Application Insights Logs.")
persis.BoolVar(&m.monitorOverview, "overview", false, "Open a browser to Application Insights Overview Dashboard.")
}
Expand Down
22 changes: 19 additions & 3 deletions cli/azd/cmd/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func pipelineCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "pipeline",
Short: "Manage GitHub Actions pipelines.",
//nolint:lll
Long: `Manage GitHub Actions pipelines.
The Azure Developer CLI template includes a GitHub Actions pipeline configuration file (in the *.github/workflows* folder) that deploys your application whenever code is pushed to the main branch.
Expand Down Expand Up @@ -65,9 +66,24 @@ func (p *pipelineConfigAction) SetupFlags(
persis *pflag.FlagSet,
local *pflag.FlagSet,
) {
local.StringVar(&p.manager.PipelineServicePrincipalName, "principal-name", "", "The name of the service principal to use to grant access to Azure resources as part of the pipeline.")
local.StringVar(&p.manager.PipelineRemoteName, "remote-name", "origin", "The name of the git remote to configure the pipeline to run on.")
local.StringVar(&p.manager.PipelineRoleName, "principal-role", "Contributor", "The role to assign to the service principal.")
local.StringVar(
&p.manager.PipelineServicePrincipalName,
"principal-name",
"",
"The name of the service principal to use to grant access to Azure resources as part of the pipeline.",
)
local.StringVar(
&p.manager.PipelineRemoteName,
"remote-name",
"origin",
"The name of the git remote to configure the pipeline to run on.",
)
local.StringVar(
&p.manager.PipelineRoleName,
"principal-role",
"Contributor",
"The role to assign to the service principal.",
)
local.StringVar(&p.manager.PipelineProvider, "provider", "", "The pipeline provider to use (GitHub and Azdo supported).")
}

Expand Down
6 changes: 5 additions & 1 deletion cli/azd/cmd/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func TestSetupFlags(t *testing.T) {
principalNameFlag := command.LocalFlags().Lookup(flagName)
assert.NotEqual(t, (*pflag.Flag)(nil), principalNameFlag)
assert.Equal(t, "", principalNameFlag.Value.String())
assert.Equal(t, "The name of the service principal to use to grant access to Azure resources as part of the pipeline.", principalNameFlag.Usage)
assert.Equal(
t,
"The name of the service principal to use to grant access to Azure resources as part of the pipeline.",
principalNameFlag.Usage,
)
principalNameFlag = command.PersistentFlags().Lookup(flagName)
assert.Equal(t, (*pflag.Flag)(nil), principalNameFlag)

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func provisionCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
"provision",
"Provision the Azure resources for an application.",
&commands.BuildOptions{
//nolint:lll
Long: `Provision the Azure resources for an application.
The command prompts you for the following:
Expand Down
9 changes: 8 additions & 1 deletion cli/azd/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func restoreCmd(rootOptions *internal.GlobalCommandOptions) *cobra.Command {
"restore",
"Restore application dependencies.",
&commands.BuildOptions{
//nolint:lll
Long: `Restore application dependencies.
Run this command to download and install all the required libraries so that you can build, run, and debug the application locally.
Expand All @@ -42,7 +43,13 @@ type restoreAction struct {
}

func (r *restoreAction) SetupFlags(persis, local *pflag.FlagSet) {
local.StringVar(&r.serviceName, "service", "", "Restores a specific service (when the string is unspecified, all services that are listed in the "+azdcontext.ProjectFileName+" file are restored).")
local.StringVar(
&r.serviceName,
"service",
"",
"Restores a specific service (when the string is unspecified, "+
"all services that are listed in the "+azdcontext.ProjectFileName+" file are restored).",
)
}

func (r *restoreAction) Run(ctx context.Context, _ *cobra.Command, args []string, azdCtx *azdcontext.AzdContext) error {
Expand Down

0 comments on commit c53a984

Please sign in to comment.