Skip to content

Commit edf380a

Browse files
authored
Merge pull request #387 from roots/new-config-file
Support new trellis.cli.yml config file
2 parents ecfa229 + e7a63d9 commit edf380a

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ Supported commands so far:
157157
There are three ways to set configuration settings for trellis-cli and they are
158158
loaded in this order of precedence:
159159
160-
1. global config
161-
2. project config
162-
3. env variables
160+
1. global config (`$HOME/.config/trellis/cli.yml`)
161+
2. project config (`trellis.cli.yml`)
162+
3. project config local override (`trellis.cli.local.yml`)
163+
4. env variables
163164
164165
The global CLI config (defaults to `$HOME/.config/trellis/cli.yml`)
165166
and will be loaded first (if it exists).
166167
167168
Next, if a project is detected, the project CLI config will be loaded if it
168-
exists at `.trellis/cli.yml`.
169+
exists at `trellis.cli.yml`. A Git ignored local override config is also
170+
supported at `trellis.cli.local.yml`.
169171
170172
Finally, env variables prefixed with `TRELLIS_` will be used as
171173
overrides if they match a supported configuration setting. The prefix will be

cmd/open.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (c *OpenCommand) Run(args []string) int {
4545
value, exists := c.Trellis.CliConfig.Open[args[0]]
4646

4747
if !exists {
48-
c.UI.Error(fmt.Sprintf("Error: shortcut '%s' does not exist. Check your .trellis/cli.yml config file.", args[0]))
48+
c.UI.Error(fmt.Sprintf("Error: shortcut '%s' does not exist in your CLI config file.", args[0]))
4949
c.UI.Error(fmt.Sprintf("Valid shortcuts are: %s", strings.Join(openNames(c.Trellis.CliConfig.Open), ", ")))
5050
return 1
5151
}
@@ -87,7 +87,7 @@ Opens user-defined URLs (and more) which can act as shortcuts/bookmarks specific
8787
8888
Without any arguments provided, this defaults to opening the main site's development canonical URL.
8989
90-
Additional entries can be customized by adding them to your project's config file (in '.trellis/cli.yml'):
90+
Additional entries can be customized by adding them to your project's config file (trellis.cli.yml):
9191
9292
open:
9393
sentry: https://myapp.sentry.io

cmd/open_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestOpenRun(t *testing.T) {
7474
{
7575
"invalid_shortcut_name",
7676
[]string{"invalid"},
77-
"Error: shortcut 'invalid' does not exist.",
77+
"Error: shortcut 'invalid' does not exist",
7878
1,
7979
},
8080
{

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ func main() {
3939

4040
trellis := trellis.NewTrellis()
4141

42-
// load global CLI config
43-
if err := trellis.LoadCliConfig(); err != nil {
42+
if err := trellis.LoadGlobalCliConfig(); err != nil {
4443
ui.Error(err.Error())
4544
os.Exit(1)
4645
}

trellis/trellis.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ func (t *Trellis) getDefaultSiteNameFromEnvironment(environment string) (siteNam
291291
return sites[0], nil
292292
}
293293

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

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

308308
func (t *Trellis) LoadProjectCliConfig() error {
309-
path := filepath.Join(t.ConfigPath(), cliConfigFile)
309+
configPaths := []string{
310+
filepath.Join(t.ConfigPath(), "cli.yml"),
311+
filepath.Join(t.Path, "trellis.cli.yml"),
312+
filepath.Join(t.Path, "trellis.cli.local.yml"),
313+
}
310314

311-
if err := t.CliConfig.LoadFile(path); err != nil {
312-
return fmt.Errorf("Error loading CLI config %s\n%v", path, err)
315+
for _, path := range configPaths {
316+
if err := t.CliConfig.LoadFile(path); err != nil {
317+
return fmt.Errorf("Error loading CLI config %s\n%v", path, err)
318+
}
313319
}
314320

315321
t.CliConfig.LoadEnv("TRELLIS_")

trellis/trellis_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func TestLoadCliConfigWhenFileDoesNotExist(t *testing.T) {
337337
t.Setenv("TRELLIS_CONFIG_DIR", tempDir)
338338

339339
tp := NewTrellis()
340-
err := tp.LoadCliConfig()
340+
err := tp.LoadGlobalCliConfig()
341341

342342
if err != nil {
343343
t.Error("expected no error")
@@ -363,7 +363,7 @@ ask_vault_pass: true
363363
t.Fatal(err)
364364
}
365365

366-
err := tp.LoadCliConfig()
366+
err := tp.LoadGlobalCliConfig()
367367

368368
if err != nil {
369369
t.Fatalf("unexpected error: %v", err)
@@ -391,7 +391,7 @@ ask_vault_pass: true
391391
t.Fatal(err)
392392
}
393393

394-
err := tp.LoadCliConfig()
394+
err := tp.LoadGlobalCliConfig()
395395

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

0 commit comments

Comments
 (0)