Skip to content

Commit

Permalink
refactor the documentation, reformat the code, new release
Browse files Browse the repository at this point in the history
  • Loading branch information
janosmiko committed Mar 2, 2022
1 parent 2a725ac commit 97f8f65
Show file tree
Hide file tree
Showing 62 changed files with 1,416 additions and 1,153 deletions.
30 changes: 15 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ linters:
- deadcode
- depguard
- dogsled
# bug:
# https://github.com/golangci/golangci-lint/issues/967
# - dupl
# bug:
# https://github.com/golangci/golangci-lint/issues/967
# - dupl
- errcheck
- exhaustive
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - goconst
# - gocritic
# - gocyclo
- godot
# - godox
# - goerr113
# - godox
# - goerr113
- gofmt
- goimports
- golint
# - gomnd
# - gomnd
- goprintffuncname
- gosec
- gosimple
Expand All @@ -46,10 +46,10 @@ linters:
- maligned
- misspell
- nakedret
# - nestif
# - nestif
- noctx
- nolintlint
# - prealloc
# - prealloc
- rowserrcheck
- scopelint
- staticcheck
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.24-beta
v0.2.25-beta
9 changes: 6 additions & 3 deletions cmd/blackfire/blackfire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package blackfire

import (
"fmt"
"strings"

"github.com/rewardenv/reward/internal/commands"
"github.com/rewardenv/reward/internal/core"
"strings"

"github.com/spf13/cobra"
)
Expand All @@ -13,10 +14,12 @@ var Cmd = &cobra.Command{
Use: "blackfire [command]",
Short: fmt.Sprintf(
"Interacts with the blackfire service on an environment (disabled if %v_BLACKFIRE is not 1)",
strings.ToUpper(core.AppName)),
strings.ToUpper(core.AppName),
),
Long: fmt.Sprintf(
`Interacts with the blackfire service on an environment (disabled if %v_BLACKFIRE is not 1)`,
strings.ToUpper(core.AppName)),
strings.ToUpper(core.AppName),
),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
},
Expand Down
30 changes: 20 additions & 10 deletions cmd/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func init() {
func addFlags() {
// --with-sampledata
Cmd.Flags().Bool(
"with-sampledata", false, "starts m2demo using demo images with sampledata")
"with-sampledata", false, "starts m2demo using demo images with sampledata",
)

_ = viper.BindPFlag(core.AppName+"_with_sampledata", Cmd.Flags().Lookup("with-sampledata"))

Expand All @@ -47,31 +48,36 @@ func addFlags() {
"no-pull",
false,
"when specified latest images will not be explicitly pulled "+
"prior to environment startup to facilitate use of locally built images")
"prior to environment startup to facilitate use of locally built images",
)

_ = viper.BindPFlag(core.AppName+"_no_pull", Cmd.Flags().Lookup("no-pull"))

// --full
Cmd.Flags().Bool(
"full", false, "includes sample data install and reindexing")
"full", false, "includes sample data install and reindexing",
)

_ = viper.BindPFlag(core.AppName+"_full_bootstrap", Cmd.Flags().Lookup("full"))

// --no-parallel
Cmd.Flags().Bool(
"no-parallel", false, "disable hirak/prestissimo composer module")
"no-parallel", false, "disable hirak/prestissimo composer module",
)

_ = viper.BindPFlag(core.AppName+"_composer_no_parallel", Cmd.Flags().Lookup("no-parallel"))

// --skip-composer-install
Cmd.Flags().Bool(
"skip-composer-install", false, "dont run composer install")
"skip-composer-install", false, "dont run composer install",
)

_ = viper.BindPFlag(core.AppName+"_skip_composer_install", Cmd.Flags().Lookup("skip-composer-install"))

// --magento-type
Cmd.Flags().String(
"magento-type", "community", "magento type to install (community or enterprise)")
"magento-type", "community", "magento type to install (community or enterprise)",
)

_ = viper.BindPFlag(core.AppName+"_magento_type", Cmd.Flags().Lookup("magento-type"))

Expand All @@ -81,25 +87,29 @@ func addFlags() {
log.Fatalln(err)
}
Cmd.Flags().String(
"magento-version", magentoVersion.String(), "magento version")
"magento-version", magentoVersion.String(), "magento version",
)

_ = viper.BindPFlag(core.AppName+"_magento_version", Cmd.Flags().Lookup("magento-version"))

// --disable-tfa
Cmd.Flags().Bool(
"disable-tfa", false, "disable magento 2 two-factor authentication")
"disable-tfa", false, "disable magento 2 two-factor authentication",
)

_ = viper.BindPFlag(core.AppName+"_magento_disable_tfa", Cmd.Flags().Lookup("disable-tfa"))

// --magento-mode
Cmd.Flags().String(
"magento-mode", "developer", "mage mode (developer or production)")
"magento-mode", "developer", "mage mode (developer or production)",
)

_ = viper.BindPFlag(core.AppName+"_magento_mode", Cmd.Flags().Lookup("magento-mode"))

// --reset-admin-url
Cmd.Flags().Bool(
"reset-admin-url", false, "set admin/url/use_custom and admin/url/use_custom_path configurations to 0")
"reset-admin-url", false, "set admin/url/use_custom and admin/url/use_custom_path configurations to 0",
)

_ = viper.BindPFlag(core.AppName+"_reset_admin_url", Cmd.Flags().Lookup("reset-admin-url"))
}
9 changes: 6 additions & 3 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package completion

import (
"fmt"
reward "github.com/rewardenv/reward/internal/core"
"os"

reward "github.com/rewardenv/reward/internal/core"

"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: fmt.Sprintf(`To load completions:
Long: fmt.Sprintf(
`To load completions:
Bash:
Expand Down Expand Up @@ -49,7 +51,8 @@ PS> %[1]v completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> %[1]v completion powershell > %[1]v.ps1
# and source this file from your powershell profile.
`, reward.AppName),
`, reward.AppName,
),
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Expand Down
18 changes: 9 additions & 9 deletions cmd/envInit/envInit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ var Cmd = &cobra.Command{
}

func init() {
flagEnvName := "environment-name"
Cmd.Flags().String(flagEnvName, " ", "name for the new environment")
// _ = Cmd.MarkFlagRequired(flagEnvName)
_ = viper.BindPFlag(core.AppName+"_env_name", Cmd.Flags().Lookup(flagEnvName))
Cmd.Flags().String("environment-name", " ", "name for the new environment")
_ = viper.BindPFlag(core.AppName+"_env_name", Cmd.Flags().Lookup("environment-name"))

flagEnvType := "environment-type"
Cmd.Flags().String(flagEnvType, "magento2", "type of the new environment")
Cmd.Flags().String("environment-type", "magento2", "type of the new environment")
_ = Cmd.RegisterFlagCompletionFunc(
flagEnvType, func(envInitCmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
"environment-type",
func(envInitCmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return commands.GetValidEnvTypes(), cobra.ShellCompDirectiveDefault
})
_ = viper.BindPFlag(core.AppName+"_env_type", Cmd.Flags().Lookup(flagEnvType))
},
)

_ = viper.BindPFlag(core.AppName+"_env_type", Cmd.Flags().Lookup("environment-type"))
}
60 changes: 36 additions & 24 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ package cmd

import (
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/rewardenv/reward/cmd/blackfire"
"github.com/rewardenv/reward/cmd/bootstrap"
Expand All @@ -35,11 +41,6 @@ import (
"github.com/rewardenv/reward/cmd/sync"
"github.com/rewardenv/reward/cmd/version"
"github.com/rewardenv/reward/internal/core"
"os"
"path"
"path/filepath"
"runtime"
"strings"

dockerClient "github.com/docker/docker/client"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -156,17 +157,19 @@ func setLogLevel() {
}
}

log.SetFormatter(&log.TextFormatter{
DisableColors: viper.GetBool("disable_colors"),
ForceColors: true,
DisableLevelTruncation: true,
FullTimestamp: true,
QuoteEmptyFields: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := strings.Replace(path.Base(f.File), "github.com/rewardenv/reward", "", 1)
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
log.SetFormatter(
&log.TextFormatter{
DisableColors: viper.GetBool("disable_colors"),
ForceColors: true,
DisableLevelTruncation: true,
FullTimestamp: true,
QuoteEmptyFields: true,
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
filename := strings.Replace(path.Base(f.File), "github.com/rewardenv/reward", "", 1)
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
},
},
})
)

}

Expand Down Expand Up @@ -231,44 +234,51 @@ func addFlags() {

// --app-dir
rootCmd.PersistentFlags().StringVar(
&appHomeDir, "app-dir", filepath.Join(home, "."+core.AppName), "app home directory")
&appHomeDir, "app-dir", filepath.Join(home, "."+core.AppName), "app home directory",
)

_ = viper.BindPFlag(core.AppName+"_home_dir", rootCmd.PersistentFlags().Lookup("app-dir"))

// --log-level
rootCmd.PersistentFlags().String(
"log-level", "info", "logging level (options: trace, debug, info, warning, error)")
"log-level", "info", "logging level (options: trace, debug, info, warning, error)",
)

_ = viper.BindPFlag("log_level", rootCmd.PersistentFlags().Lookup("log-level"))

// --debug
rootCmd.PersistentFlags().Bool(
"debug", false, "enable debug mode (same as --log-level=debug)")
"debug", false, "enable debug mode (same as --log-level=debug)",
)

_ = viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))

// --disable-colors
rootCmd.PersistentFlags().Bool(
"disable-colors", false, "disable colors in output")
"disable-colors", false, "disable colors in output",
)

_ = viper.BindPFlag("disable_colors", rootCmd.PersistentFlags().Lookup("disable-colors"))

// --config
rootCmd.PersistentFlags().StringVarP(
&cfgFile, "config", "c", filepath.Join(core.GetHomeDir(), "."+core.AppName+".yml"), "config file")
&cfgFile, "config", "c", filepath.Join(core.GetHomeDir(), "."+core.AppName+".yml"), "config file",
)

_ = viper.BindPFlag(core.AppName+"_config_file", rootCmd.PersistentFlags().Lookup("config"))

// --docker-host
rootCmd.PersistentFlags().String(
"docker-host", dockerClient.DefaultDockerHost, "docker host")
"docker-host", dockerClient.DefaultDockerHost, "docker host",
)

_ = viper.BindPFlag("docker_host", rootCmd.PersistentFlags().Lookup("docker-host"))

if core.GetOSDistro() == "windows" {
// --docker-host
rootCmd.PersistentFlags().Bool(
"wsl2-direct-mount", false, "use direct mount in WSL2 instead of syncing")
"wsl2-direct-mount", false, "use direct mount in WSL2 instead of syncing",
)

_ = viper.BindPFlag(core.AppName+"_wsl2_direct_mount", rootCmd.PersistentFlags().Lookup("wsl2-direct-mount"))
}
Expand All @@ -280,15 +290,17 @@ func addFlags() {

// --service-domain
rootCmd.PersistentFlags().String(
"service-domain", core.AppName+".test", "service domain for global services")
"service-domain", core.AppName+".test", "service domain for global services",
)

rootCmd.PersistentFlags().Lookup("service-domain").Hidden = true

_ = viper.BindPFlag(core.AppName+"_service_domain", rootCmd.PersistentFlags().Lookup("service-domain"))

// --print-environment
rootCmd.Flags().Bool(
"print-environment", false, "environment vars")
"print-environment", false, "environment vars",
)

_ = viper.BindPFlag(core.AppName+"_print_environment", rootCmd.Flags().Lookup("print-environment"))
}
3 changes: 2 additions & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package version
import (
"context"
"fmt"
"github.com/rewardenv/reward/internal/core"
"strings"

"github.com/rewardenv/reward/internal/core"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down
Loading

0 comments on commit 97f8f65

Please sign in to comment.