Skip to content

Commit

Permalink
style: format code by gofumpt
Browse files Browse the repository at this point in the history
https://github.com/mvdan/gofumpt

```sh
git ls-files | grep -E "\.go$" |
  xargs gofumpt -l -s -w
```
  • Loading branch information
suzuki-shunsuke committed Jan 29, 2025
1 parent 255a05a commit 9638fae
Show file tree
Hide file tree
Showing 71 changed files with 172 additions and 250 deletions.
14 changes: 6 additions & 8 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func processCustomCommands(
if _, exist := existingTopLevelCommands[commandConfig.Name]; exist && topLevel {
command = existingTopLevelCommands[commandConfig.Name]
} else {
var customCommand = &cobra.Command{
customCommand := &cobra.Command{
Use: commandConfig.Name,
Short: commandConfig.Description,
Long: commandConfig.Description,
Expand Down Expand Up @@ -132,7 +132,7 @@ func processCommandAliases(
aliasCmd := strings.TrimSpace(v)
aliasFor := fmt.Sprintf("alias for '%s'", aliasCmd)

var aliasCommand = &cobra.Command{
aliasCommand := &cobra.Command{
Use: alias,
Short: aliasFor,
Long: aliasFor,
Expand Down Expand Up @@ -170,7 +170,7 @@ func preCustomCommand(
) {
var sb strings.Builder

//checking for zero arguments in config
// checking for zero arguments in config
if len(commandConfig.Arguments) == 0 {
if len(commandConfig.Steps) > 0 {
// do nothing here; let the code proceed
Expand All @@ -193,7 +193,7 @@ func preCustomCommand(
}
}

//Check on many arguments required and have no default value
// Check on many arguments required and have no default value
requiredNoDefaultCount := 0
for _, arg := range commandConfig.Arguments {
if arg.Required && arg.Default == "" {
Expand Down Expand Up @@ -310,7 +310,7 @@ func executeCustomCommand(
}

// Prepare template data
var data = map[string]any{
data := map[string]any{
"Arguments": argumentsData,
"Flags": flagsData,
}
Expand Down Expand Up @@ -536,7 +536,6 @@ func CheckForAtmosUpdateAndPrintMessage(atmosConfig schema.AtmosConfiguration) {
cacheCfg.LastChecked = time.Now().Unix()
if saveErr := cfg.SaveCache(cacheCfg); saveErr != nil {
u.LogWarning(atmosConfig, fmt.Sprintf("Unable to save cache: %s", saveErr))

}
}

Expand All @@ -554,7 +553,6 @@ func handleHelpRequest(cmd *cobra.Command, args []string) {
}

func showUsageAndExit(cmd *cobra.Command, args []string) {

var suggestions []string
unknownCommand := fmt.Sprintf("Error: Unknown command: %q\n\n", cmd.CommandPath())

Expand Down Expand Up @@ -593,7 +591,7 @@ func getConfigAndStacksInfo(commandName string, cmd *cobra.Command, args []strin
checkAtmosConfig()

var argsAfterDoubleDash []string
var finalArgs = args
finalArgs := args

doubleDashIndex := lo.IndexOf(args, "--")
if doubleDashIndex > 0 {
Expand Down
3 changes: 0 additions & 3 deletions cmd/colored/colored.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Config struct {

// Init patches Cobra's usage template with configuration provided.
func Init(cfg *Config) {

if cfg.RootCmd == nil {
panic("coloredcobra: Root command pointer is missing.")
}
Expand Down Expand Up @@ -147,7 +146,6 @@ func Init(cfg *Config) {
if cf != nil || cfd != nil || cfdt != nil {

cobra.AddTemplateFunc("FlagStyle", func(s string) string {

// Flags info section is multi-line.
// Let's split these lines and iterate them.
lines := strings.Split(s, "\n")
Expand Down Expand Up @@ -193,7 +191,6 @@ func Init(cfg *Config) {
s = strings.Join(lines, "\n")

return s

})

// Patch usage template
Expand Down
1 change: 0 additions & 1 deletion cmd/describe_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var describeConfigCmd = &cobra.Command{
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {

err := e.ExecuteDescribeConfigCmd(cmd, args)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
Expand Down
1 change: 0 additions & 1 deletion cmd/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var describeStacksCmd = &cobra.Command{
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {

// Check Atmos configuration
checkAtmosConfig()

Expand Down
6 changes: 4 additions & 2 deletions cmd/helmfile_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
)

// Command: atmos helmfile apply
var helmfileApplyShort = "Apply changes to align the actual state of Helm releases with the desired state."
var helmfileApplyLong = `This command reconciles the actual state of Helm releases in the cluster with the desired state
var (
helmfileApplyShort = "Apply changes to align the actual state of Helm releases with the desired state."
helmfileApplyLong = `This command reconciles the actual state of Helm releases in the cluster with the desired state
defined in your configurations by applying the necessary changes.
Example usage:
atmos helmfile apply echo-server -s tenant1-ue2-dev
atmos helmfile apply echo-server -s tenant1-ue2-dev --redirect-stderr /dev/stdout`
)

// helmfileApplyCmd represents the base command for all helmfile sub-commands
var helmfileApplyCmd = &cobra.Command{
Expand Down
6 changes: 4 additions & 2 deletions cmd/helmfile_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package cmd
import "github.com/spf13/cobra"

// Command: atmos helmfile destroy
var helmfileDestroyShort = "Destroy the Helm releases for the specified stack."
var helmfileDestroyLong = `This command removes the specified Helm releases from the cluster, ensuring a clean state for
var (
helmfileDestroyShort = "Destroy the Helm releases for the specified stack."
helmfileDestroyLong = `This command removes the specified Helm releases from the cluster, ensuring a clean state for
the given stack.
Example usage:
atmos helmfile destroy echo-server --stack=tenant1-ue2-dev
atmos helmfile destroy echo-server --stack=tenant1-ue2-dev --redirect-stderr /dev/stdout`
)

// helmfileDestroyCmd represents the base command for all helmfile sub-commands
var helmfileDestroyCmd = &cobra.Command{
Expand Down
6 changes: 4 additions & 2 deletions cmd/helmfile_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
)

// Command: atmos helmfile diff
var helmfileDiffShort = "Show differences between the desired and actual state of Helm releases."
var helmfileDiffLong = `This command calculates and displays the differences between the desired state of Helm releases
var (
helmfileDiffShort = "Show differences between the desired and actual state of Helm releases."
helmfileDiffLong = `This command calculates and displays the differences between the desired state of Helm releases
defined in your configurations and the actual state deployed in the cluster.
Example usage:
atmos helmfile diff echo-server -s tenant1-ue2-dev
atmos helmfile diff echo-server -s tenant1-ue2-dev --redirect-stderr /dev/null`
)

// helmfileDiffCmd represents the base command for all helmfile sub-commands
var helmfileDiffCmd = &cobra.Command{
Expand Down
6 changes: 4 additions & 2 deletions cmd/helmfile_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package cmd
import "github.com/spf13/cobra"

// Command: atmos helmfile sync
var helmfileSyncShort = "Synchronize the state of Helm releases with the desired state without making changes."
var helmfileSyncLong = `This command ensures that the actual state of Helm releases in the cluster matches the desired
var (
helmfileSyncShort = "Synchronize the state of Helm releases with the desired state without making changes."
helmfileSyncLong = `This command ensures that the actual state of Helm releases in the cluster matches the desired
state defined in your configurations without performing destructive actions.
Example usage:
atmos helmfile sync echo-server --stack tenant1-ue2-dev
atmos helmfile sync echo-server --stack tenant1-ue2-dev --redirect-stderr ./errors.txt`
)

// helmfileSyncCmd represents the base command for all helmfile sub-commands
var helmfileSyncCmd = &cobra.Command{
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func initCobraConfig() {
return nil
})
RootCmd.SetHelpFunc(func(command *cobra.Command, args []string) {

if !(Contains(os.Args, "help") || Contains(os.Args, "--help") || Contains(os.Args, "-h")) {
arguments := os.Args[len(strings.Split(command.CommandPath(), " ")):]
if len(command.Flags().Args()) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate_editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var editorConfigCmd *cobra.Command = &cobra.Command{
func initializeConfig(cmd *cobra.Command) {
replaceAtmosConfigInConfig(cmd, atmosConfig)

var configPaths = []string{}
configPaths := []string{}
if configFilePath == "" {
configPaths = append(configPaths, defaultConfigFileNames[:]...)
} else {
Expand Down
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func ExecuteAtlantisGenerateRepoConfig(
stacks []string,
components []string,
) error {

stacksMap, _, err := FindStacksMap(atmosConfig, false)
if err != nil {
return err
Expand Down Expand Up @@ -507,7 +506,7 @@ func ExecuteAtlantisGenerateRepoConfig(
return err
}

err = u.WriteToFileAsYAML(fileAbsolutePath, atlantisYaml, 0644)
err = u.WriteToFileAsYAML(fileAbsolutePath, atlantisYaml, 0o644)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion internal/exec/atlantis_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func BuildAtlantisProjectNameFromComponentConfig(
atmosConfig schema.AtmosConfiguration,
configAndStacksInfo schema.ConfigAndStacksInfo,
) (string, error) {

var atlantisProjectTemplate schema.AtlantisProjectConfig
var atlantisProjectName string

Expand Down
7 changes: 0 additions & 7 deletions internal/exec/config_sources_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func processSectionValueInStacks(
subsection string,
value string,
) schema.ConfigSourcesStackDependencies {

result := schema.ConfigSourcesStackDependencies{}

// Process the value for the component in the stack
Expand Down Expand Up @@ -231,7 +230,6 @@ func processComponentSectionValueInStack(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down Expand Up @@ -327,7 +325,6 @@ func processComponentTypeSectionValueInStack(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down Expand Up @@ -402,7 +399,6 @@ func processGlobalSectionValueInStack(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down Expand Up @@ -468,7 +464,6 @@ func processComponentSectionValueInStackImports(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down Expand Up @@ -578,7 +573,6 @@ func processComponentTypeSectionValueInStackImports(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down Expand Up @@ -667,7 +661,6 @@ func processGlobalSectionValueInStackImports(
subsection string,
value string,
) *schema.ConfigSourcesStackDependencies {

rawStackConfig, ok := rawStackConfigs[stackFile]
if !ok {
return result
Expand Down
13 changes: 0 additions & 13 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func ExecuteDescribeAffectedWithTargetRefClone(
includeSettings bool,
stack string,
) ([]schema.Affected, *plumbing.Reference, *plumbing.Reference, string, error) {

if verbose {
atmosConfig.Logs.Level = u.LogLevelTrace
}
Expand Down Expand Up @@ -184,7 +183,6 @@ func ExecuteDescribeAffectedWithTargetRefCheckout(
includeSettings bool,
stack string,
) ([]schema.Affected, *plumbing.Reference, *plumbing.Reference, string, error) {

if verbose {
atmosConfig.Logs.Level = u.LogLevelTrace
}
Expand Down Expand Up @@ -335,7 +333,6 @@ func ExecuteDescribeAffectedWithTargetRepoPath(
includeSettings bool,
stack string,
) ([]schema.Affected, *plumbing.Reference, *plumbing.Reference, string, error) {

localRepo, err := g.GetLocalRepo()
if err != nil {
return nil, nil, nil, "", err
Expand Down Expand Up @@ -389,7 +386,6 @@ func executeDescribeAffected(
includeSettings bool,
stack string,
) ([]schema.Affected, *plumbing.Reference, *plumbing.Reference, error) {

if verbose {
atmosConfig.Logs.Level = u.LogLevelTrace
}
Expand Down Expand Up @@ -529,7 +525,6 @@ func findAffected(
includeSettings bool,
stackToFilter string,
) ([]schema.Affected, error) {

res := []schema.Affected{}
var err error

Expand Down Expand Up @@ -741,7 +736,6 @@ func findAffected(
changedFiles,
stackComponentSettings.DependsOn,
)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -955,7 +949,6 @@ func findAffected(
changedFiles,
stackComponentSettings.DependsOn,
)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1018,7 +1011,6 @@ func appendToAffected(
stacks map[string]any,
includeSettings bool,
) ([]schema.Affected, error) {

// If the affected component in the stack was already added to the result, don't add it again
for _, v := range affectedList {
if v.Component == affected.Component && v.Stack == affected.Stack && v.ComponentType == affected.ComponentType {
Expand Down Expand Up @@ -1101,7 +1093,6 @@ func isEqual(
localSection map[string]any,
sectionName string,
) bool {

if remoteStackSection, ok := remoteStacks[localStackName].(map[string]any); ok {
if remoteComponentsSection, ok := remoteStackSection["components"].(map[string]any); ok {
if remoteComponentTypeSection, ok := remoteComponentsSection[componentType].(map[string]any); ok {
Expand All @@ -1123,7 +1114,6 @@ func isComponentDependentFolderOrFileChanged(
changedFiles []string,
deps schema.DependsOn,
) (bool, string, string, error) {

hasDependencies := false
isChanged := false
changedType := ""
Expand Down Expand Up @@ -1184,7 +1174,6 @@ func isComponentFolderChanged(
atmosConfig schema.AtmosConfiguration,
changedFiles []string,
) (bool, error) {

var componentPath string

switch componentType {
Expand Down Expand Up @@ -1226,7 +1215,6 @@ func areTerraformComponentModulesChanged(
atmosConfig schema.AtmosConfiguration,
changedFiles []string,
) (bool, error) {

componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)

componentPathAbs, err := filepath.Abs(componentPath)
Expand Down Expand Up @@ -1282,7 +1270,6 @@ func addAffectedSpaceliftAdminStack(
configAndStacksInfo schema.ConfigAndStacksInfo,
includeSettings bool,
) ([]schema.Affected, error) {

// Convert the `settings` section to the `Settings` structure
var componentSettings schema.Settings
err := mapstructure.Decode(settingsSection, &componentSettings)
Expand Down
Loading

0 comments on commit 9638fae

Please sign in to comment.