Skip to content

Commit 1cb2a61

Browse files
authored
Relative paths for config (#43)
1 parent ead21be commit 1cb2a61

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

internal/cmd/flags.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
package cmd
22

33
import (
4-
"os"
5-
"path"
6-
74
"github.com/openshift-knative/deviate/pkg/cli"
85
"github.com/openshift-knative/deviate/pkg/metadata"
96
"github.com/spf13/cobra"
107
)
118

129
func addFlags(root *cobra.Command, opts *cli.Options) {
1310
fl := root.PersistentFlags()
14-
wd, err := os.Getwd()
15-
if err != nil {
16-
panic(err)
17-
}
18-
config := path.Join(wd, ".deviate.yaml")
19-
fl.StringVar(&opts.ConfigPath, "config", config,
11+
fl.StringVar(&opts.ConfigPath, "config", ".deviate.yaml",
2012
metadata.Name+" configuration file")
2113
}

internal/cmd/sync.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"os"
45
"path"
56

67
"github.com/openshift-knative/deviate/pkg/cli"
@@ -29,9 +30,17 @@ func (s sync) run(cmd *cobra.Command, args []string) error {
2930

3031
func (s sync) project(args []string) func() config.Project {
3132
return func() config.Project {
33+
configPath := s.ConfigPath
34+
wd, err := os.Getwd()
35+
if err != nil {
36+
wd = "/"
37+
}
38+
if !path.IsAbs(configPath) {
39+
configPath = path.Join(wd, configPath)
40+
}
3241
project := config.Project{
33-
ConfigPath: s.ConfigPath,
34-
Path: path.Dir(s.ConfigPath),
42+
ConfigPath: configPath,
43+
Path: wd,
3544
}
3645
if len(args) > 0 {
3746
project.Path = args[0]

0 commit comments

Comments
 (0)