Skip to content

Commit

Permalink
Support .trellis.cli.yml config file
Browse files Browse the repository at this point in the history
Adds more supported config files. In order of precedence, the following
paths will be loaded:

* `.trellis/cli.yml` - existing file, now considered deprecated
* `.trellis.cli.yml` - new path
* `.trellis.local.cli.yml` - optional local override config

This change is being done to allow the `.trellis` directory to be
gitigored as it contains CLI generated files that are machine specific
and should not be committed to Git.
  • Loading branch information
swalkinshaw committed Apr 16, 2023
1 parent ecfa229 commit 15f50b2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *OpenCommand) Run(args []string) int {
value, exists := c.Trellis.CliConfig.Open[args[0]]

if !exists {
c.UI.Error(fmt.Sprintf("Error: shortcut '%s' does not exist. Check your .trellis/cli.yml config file.", args[0]))
c.UI.Error(fmt.Sprintf("Error: shortcut '%s' does not exist in your CLI config file.", args[0]))
c.UI.Error(fmt.Sprintf("Valid shortcuts are: %s", strings.Join(openNames(c.Trellis.CliConfig.Open), ", ")))
return 1
}
Expand Down Expand Up @@ -87,7 +87,7 @@ Opens user-defined URLs (and more) which can act as shortcuts/bookmarks specific
Without any arguments provided, this defaults to opening the main site's development canonical URL.
Additional entries can be customized by adding them to your project's config file (in '.trellis/cli.yml'):
Additional entries can be customized by adding them to your project's config file (in '.trellis.cli.yml'):
open:
sentry: https://myapp.sentry.io
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func main() {

trellis := trellis.NewTrellis()

// load global CLI config
if err := trellis.LoadCliConfig(); err != nil {
if err := trellis.LoadGlobalCliConfig(); err != nil {
ui.Error(err.Error())
os.Exit(1)
}
Expand Down
16 changes: 11 additions & 5 deletions trellis/trellis.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ func (t *Trellis) getDefaultSiteNameFromEnvironment(environment string) (siteNam
return sites[0], nil
}

func (t *Trellis) LoadCliConfig() error {
path := app_paths.ConfigPath(cliConfigFile)
func (t *Trellis) LoadGlobalCliConfig() error {
path := app_paths.ConfigPath("cli.yml")

if err := t.CliConfig.LoadFile(path); err != nil {
return fmt.Errorf("Error loading CLI config %s\n\n%v", path, err)
Expand All @@ -306,10 +306,16 @@ func (t *Trellis) LoadCliConfig() error {
}

func (t *Trellis) LoadProjectCliConfig() error {
path := filepath.Join(t.ConfigPath(), cliConfigFile)
configPaths := []string{
filepath.Join(t.ConfigPath(), "cli.yml"),
filepath.Join(t.Path, ".trellis.cli.yml"),
filepath.Join(t.Path, ".trellis.local.cli.yml"),
}

if err := t.CliConfig.LoadFile(path); err != nil {
return fmt.Errorf("Error loading CLI config %s\n%v", path, err)
for _, path := range configPaths {
if err := t.CliConfig.LoadFile(path); err != nil {
return fmt.Errorf("Error loading CLI config %s\n%v", path, err)
}
}

t.CliConfig.LoadEnv("TRELLIS_")
Expand Down
6 changes: 3 additions & 3 deletions trellis/trellis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestLoadCliConfigWhenFileDoesNotExist(t *testing.T) {
t.Setenv("TRELLIS_CONFIG_DIR", tempDir)

tp := NewTrellis()
err := tp.LoadCliConfig()
err := tp.LoadGlobalCliConfig()

if err != nil {
t.Error("expected no error")
Expand All @@ -363,7 +363,7 @@ ask_vault_pass: true
t.Fatal(err)
}

err := tp.LoadCliConfig()
err := tp.LoadGlobalCliConfig()

if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -391,7 +391,7 @@ ask_vault_pass: true
t.Fatal(err)
}

err := tp.LoadCliConfig()
err := tp.LoadGlobalCliConfig()

if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down

0 comments on commit 15f50b2

Please # to comment.