@@ -30,12 +30,9 @@ const (
30
30
configOptionName = "config-file"
31
31
)
32
32
33
- var (
34
- errRepoExists = errors .New (`ipfs configuration file already exists!
33
+ var errRepoExists = errors .New (`ipfs configuration file already exists!
35
34
Reinitializing would overwrite your keys.
36
35
` )
37
- errInitConfigArgs = errors .New ("Config file <-> Profile merging not implemented" )
38
- )
39
36
40
37
var initCmd = & cmds.Command {
41
38
Helptext : cmds.HelpText {
@@ -113,40 +110,40 @@ environment variable:
113
110
}
114
111
115
112
cfgLocation , _ := req .Options [configOptionName ].(string )
116
- profile , _ := req .Options [profileOptionName ].(string )
113
+ profiles , _ := req .Options [profileOptionName ].(string )
117
114
118
115
if cfgLocation != "" {
119
- if profile != "" {
120
- return errInitConfigArgs
121
- }
122
-
123
116
conf , err := cserial .Load (cfgLocation )
124
117
if err != nil {
125
118
return err
126
119
}
127
120
128
- return doInit (os .Stdout , cctx .ConfigRoot , false , nBitsForKeypairDefault , nil , conf )
129
- }
130
-
131
- var profiles []string
132
- if profile != "" {
133
- profiles = strings .Split (profile , "," )
121
+ return doInit (os .Stdout , cctx .ConfigRoot , false , nBitsForKeypairDefault , profiles , conf )
134
122
}
135
123
136
124
return doInit (os .Stdout , cctx .ConfigRoot , empty , nBitsForKeypair , profiles , conf )
137
125
},
138
126
}
139
127
140
- func initWithDefaults (out io.Writer , repoRoot string , profile string ) error {
141
- var profiles []string
142
- if profile != "" {
143
- profiles = strings .Split (profile , "," )
128
+ func applyProfiles (conf * config.Config , profiles string ) error {
129
+ if profiles == "" {
130
+ return nil
144
131
}
145
132
146
- return doInit (out , repoRoot , false , nBitsForKeypairDefault , profiles , nil )
133
+ for _ , profile := range strings .Split (profiles , "," ) {
134
+ transformer , ok := config .Profiles [profile ]
135
+ if ! ok {
136
+ return fmt .Errorf ("invalid configuration profile: %s" , profile )
137
+ }
138
+
139
+ if err := transformer .Transform (conf ); err != nil {
140
+ return err
141
+ }
142
+ }
143
+ return nil
147
144
}
148
145
149
- func doInit (out io.Writer , repoRoot string , empty bool , nBitsForKeypair int , confProfiles [] string , conf * config.Config ) error {
146
+ func doInit (out io.Writer , repoRoot string , empty bool , nBitsForKeypair int , confProfiles string , conf * config.Config ) error {
150
147
if _ , err := fmt .Fprintf (out , "initializing IPFS node at %s\n " , repoRoot ); err != nil {
151
148
return err
152
149
}
@@ -167,15 +164,8 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
167
164
}
168
165
}
169
166
170
- for _ , profile := range confProfiles {
171
- transformer , ok := config .Profiles [profile ]
172
- if ! ok {
173
- return fmt .Errorf ("invalid configuration profile: %s" , profile )
174
- }
175
-
176
- if err := transformer .Transform (conf ); err != nil {
177
- return err
178
- }
167
+ if err := applyProfiles (conf , confProfiles ); err != nil {
168
+ return err
179
169
}
180
170
181
171
if err := fsrepo .Init (repoRoot , conf ); err != nil {
0 commit comments