Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
🌱 Shorten defaultConfig to conf
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonehusin committed Mar 25, 2022
1 parent 70b5c28 commit 1fe60eb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions command/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var Root = &cobra.Command{
Use: "bindl",
Long: "Bindl is a static binary downloader for project development and infrastructure.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := envconfig.Process("BINDL", defaultConfig); err != nil {
if err := envconfig.Process("BINDL", conf); err != nil {
return err
}

var logLevel string
switch {
case defaultConfig.Silent:
case conf.Silent:
logLevel = "disabled"
case defaultConfig.Debug:
case conf.Debug:
logLevel = "debug"
default:
logLevel = "info"
Expand All @@ -53,7 +53,7 @@ var Root = &cobra.Command{
},
}

var defaultConfig = &config.Runtime{
var conf = &config.Runtime{
Path: "./bindl.yaml",
LockfilePath: "./.bindl-lock.yaml",
BinDir: "./bin",
Expand All @@ -67,11 +67,11 @@ var defaultConfig = &config.Runtime{
}

func init() {
Root.PersistentFlags().StringVarP(&defaultConfig.Path, "config", "c", defaultConfig.Path, "path to configuration file")
Root.PersistentFlags().StringVarP(&defaultConfig.LockfilePath, "lock", "l", defaultConfig.LockfilePath, "path to lockfile")
Root.PersistentFlags().StringVarP(&defaultConfig.BinDir, "bin", "b", defaultConfig.BinDir, "directory in PATH to add binaries")
Root.PersistentFlags().StringVar(&defaultConfig.ProgDir, "prog", defaultConfig.ProgDir, "directory to save real binary content")
Root.PersistentFlags().StringVarP(&conf.Path, "config", "c", conf.Path, "path to configuration file")
Root.PersistentFlags().StringVarP(&conf.LockfilePath, "lock", "l", conf.LockfilePath, "path to lockfile")
Root.PersistentFlags().StringVarP(&conf.BinDir, "bin", "b", conf.BinDir, "directory in PATH to add binaries")
Root.PersistentFlags().StringVar(&conf.ProgDir, "prog", conf.ProgDir, "directory to save real binary content")

Root.PersistentFlags().BoolVarP(&defaultConfig.Silent, "silent", "s", defaultConfig.Silent, "silence logs")
Root.PersistentFlags().BoolVar(&defaultConfig.Debug, "debug", defaultConfig.Debug, "show debug logs")
Root.PersistentFlags().BoolVarP(&conf.Silent, "silent", "s", conf.Silent, "silence logs")
Root.PersistentFlags().BoolVar(&conf.Debug, "debug", conf.Debug, "show debug logs")
}
2 changes: 1 addition & 1 deletion command/cli/generate_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For example, with default output directory "bin":
Supports typical ignore files. e.g. .dockerignore`,
RunE: func(cmd *cobra.Command, args []string) error {
return command.UpdateIgnoreFile(defaultConfig, bindlGenerateIgnorePath)
return command.UpdateIgnoreFile(conf, bindlGenerateIgnorePath)
},
}

Expand Down
2 changes: 1 addition & 1 deletion command/cli/generate_make.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ in your other rules. For example:
Calling the imported rules also works on 'make' CLI.`,
RunE: func(cmd *cobra.Command, args []string) error {
return command.GenerateMakefile(defaultConfig, bindlGenerateMakefilePath)
return command.GenerateMakefile(conf, bindlGenerateMakefilePath)
},
}

Expand Down
4 changes: 2 additions & 2 deletions command/cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ will be selected.`,
RunE: func(cmd *cobra.Command, names []string) error {
err := command.IterateLockfilePrograms(
cmd.Context(),
defaultConfig,
conf,
names,
command.Get)
if err == nil {
internal.Msgf("✨ Program(s) were downloaded, ensure that %s is in your $PATH to use properly.\n", defaultConfig.BinDir)
internal.Msgf("✨ Program(s) were downloaded, ensure that %s is in your $PATH to use properly.\n", conf.BinDir)
}
return err
},
Expand Down
2 changes: 1 addition & 1 deletion command/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var BindlList = &cobra.Command{
Args: cobra.NoArgs,

RunE: func(cmd *cobra.Command, args []string) error {
l, err := config.ParseLock(defaultConfig.LockfilePath)
l, err := config.ParseLock(conf.LockfilePath)
if err != nil {
return fmt.Errorf("parsing lockfile: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion command/cli/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var BindlPurge = &cobra.Command{
Long: `Remove downloaded programs from cache, which are not listed in the lockfile.
Passing --all would remove all existing programs regardless of lockfile.`,
RunE: func(cmd *cobra.Command, names []string) error {
return command.Purge(cmd.Context(), defaultConfig, bindlPurgeAll, bindlPurgeDryRun)
return command.Purge(cmd.Context(), conf, bindlPurgeAll, bindlPurgeDryRun)
},
}

Expand Down
2 changes: 1 addition & 1 deletion command/cli/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ file specifications (i.e. bindl.yaml), ensuring that checksums exists in
lockfile for all desired platforms and programs.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return command.Sync(cmd.Context(), defaultConfig, bindlSyncStdout)
return command.Sync(cmd.Context(), conf, bindlSyncStdout)
},
}

Expand Down
2 changes: 1 addition & 1 deletion command/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ will be selected.`,
RunE: func(cmd *cobra.Command, names []string) error {
return command.IterateLockfilePrograms(
cmd.Context(),
defaultConfig,
conf,
names,
command.Verify)
},
Expand Down

0 comments on commit 1fe60eb

Please sign in to comment.