Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
adds ability to define custom path to config
Browse files Browse the repository at this point in the history
Signed-off-by: Jason McCallister <jason@craftcms.com>
  • Loading branch information
jasonmccallister committed Apr 5, 2020
1 parent 42f6a1b commit 9b2625a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ var (
if err := validate.PHPVersion(phpVersion); err != nil {
return err
}
if err := validate.DatabaseEngine(dbEngine); err != nil {
if err := validate.DatabaseEngineAndVersion(dbEngine, dbVersion); err != nil {
return err
}

if flagDyRun {
if flagDebug {
fmt.Println("--- DEBUG ---")
fmt.Println("machine:", name)
fmt.Println("cpus:", cpus)
Expand Down
21 changes: 14 additions & 7 deletions internal/cmd/nitro.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

"github.com/mitchellh/go-homedir"
Expand All @@ -9,8 +10,9 @@ import (
)

var (
flagConfigFile string
flagMachineName string
flagDyRun bool
flagDebug bool

nitroCommand = &cobra.Command{
Use: "nitro",
Expand All @@ -24,7 +26,8 @@ func init() {

// set persistent flags on the root command
nitroCommand.PersistentFlags().StringVarP(&flagMachineName, "machine", "m", "", "name of machine")
nitroCommand.PersistentFlags().BoolVarP(&flagDyRun, "dry-run", "d", false, "bypass executing the commands")
nitroCommand.PersistentFlags().BoolVarP(&flagDebug, "debug", "d", false, "bypass executing the commands")
nitroCommand.PersistentFlags().StringVarP(&flagConfigFile, "config-file", "f", "", "configuration file to use")

// add commands to root
nitroCommand.AddCommand(
Expand Down Expand Up @@ -57,13 +60,17 @@ func Execute() {
}

func loadConfig() {
home, _ := homedir.Dir()
if flagConfigFile != "" {
viper.SetConfigFile(flagConfigFile)
} else {
home, _ := homedir.Dir()

viper.AddConfigPath(home + "/" + ".nitro")
viper.SetConfigName("nitro")
viper.SetConfigType("yaml")
viper.AddConfigPath(home + "/" + ".nitro")
viper.SetConfigName("nitro")
viper.SetConfigType("yaml")
}

if err := viper.ReadInConfig(); err == nil {
// fmt.Println("Using config file:", viper.ConfigFileUsed())
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}

0 comments on commit 9b2625a

Please # to comment.