File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ type HttpProvider struct {
128128}
129129
130130type NpmProvider struct {
131- GlobalFolders []string `yaml:"globalFolders" name:"global-folders" explode:"global-folders "`
131+ GlobalFolders []string `yaml:"globalFolders" name:"global-folders" explode:"global-folder "`
132132 Packages []NpmPackage `explode:"package"`
133133}
134134
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ func (f *flagConfigBinder) setValue(ctx *bindContext) error {
5050 }
5151 err := ctx .setFieldFromStruct ()
5252 if err != nil {
53+ if len (ctx .paths ) > 1 {
54+ ctx .paths = []string {strings .Join (ctx .paths , "-" )}
55+ }
5356 if len (ctx .paths ) == 1 {
5457 if arr , ok := ctx .value .([]string ); ok {
5558 return f .explode (ctx .element , ctx .paths [0 ], arr )
Original file line number Diff line number Diff line change 44 "mokapi/config/static"
55 "mokapi/pkg/cli"
66 "mokapi/pkg/cmd/mokapi"
7+ "os"
78 "testing"
89
910 "github.com/stretchr/testify/require"
@@ -64,3 +65,25 @@ func TestRoot_Providers_Npm(t *testing.T) {
6465 })
6566 }
6667}
68+
69+ func TestProviderNpm_Env (t * testing.T ) {
70+ key := "MOKAPI_PROVIDERS_NPM_GLOBAL_FOLDER"
71+ err := os .Setenv (key , "/npm" )
72+ require .NoError (t , err )
73+ t .Cleanup (func () {
74+ _ = os .Unsetenv (key )
75+ })
76+
77+ cmd := mokapi .NewCmdMokapi ()
78+ cmd .SetArgs ([]string {})
79+
80+ cfg := static .NewConfig ()
81+ cmd .Run = func (cmd * cli.Command , args []string ) error {
82+ cfg = cmd .Config .(* static.Config )
83+ return nil
84+ }
85+ err = cmd .Execute ()
86+ require .NoError (t , err )
87+
88+ require .Equal (t , []string {"/npm" }, cfg .Providers .Npm .GlobalFolders )
89+ }
You can’t perform that action at this time.
0 commit comments