Skip to content

Commit d9ab9b5

Browse files
author
Lachlan Donald
committed
fix: restore cli setup before github auth
1 parent 3f71c3d commit d9ab9b5

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

app/main.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ func Main(config Config) {
207207

208208
ctx, err := parser.Parse(os.Args[1:])
209209
parser.FatalIfErrorf(err)
210-
configureLogging(cli, ctx.Command(), p)
210+
configureLogging(cli, ctx, p)
211211

212-
var userConfig UserConfig
212+
userConfig := NewUserConfigWithDefaults()
213213
userConfigPath := cli.getUserConfigFile()
214214

215215
if IsUserConfigExists(userConfigPath) {
@@ -231,7 +231,10 @@ func Main(config Config) {
231231
}
232232

233233
// Initialize GitHub auth provider if needed
234-
var githubAuthProvider auth.Provider
234+
var (
235+
githubAuthProvider auth.Provider
236+
githubToken string
237+
)
235238
if envInfo != nil && len(envInfo.Config.GitHubTokenAuth.Match) > 0 {
236239
providerType := auth.ProviderTypeEnv
237240
if userConfig.GHCliAuth {
@@ -242,6 +245,11 @@ func Main(config Config) {
242245
p.Fatalf("Failed to create GitHub auth provider: %v", err)
243246
}
244247
githubAuthProvider = provider
248+
if token, tokenErr := provider.GetToken(); tokenErr != nil {
249+
p.Tracef("GitHub auth provider %s did not return token: %v", providerType, tokenErr)
250+
} else {
251+
githubToken = token
252+
}
245253
}
246254

247255
getSource := config.PackageSourceSelector
@@ -275,23 +283,6 @@ func Main(config Config) {
275283
log.Fatalf("failed to open cache: %s", err)
276284
}
277285

278-
ctx, err := parser.Parse(os.Args[1:])
279-
parser.FatalIfErrorf(err)
280-
configureLogging(cli, ctx, p)
281-
282-
userConfig := NewUserConfigWithDefaults()
283-
userConfigPath := cli.getUserConfigFile()
284-
285-
if IsUserConfigExists(userConfigPath) {
286-
p.Tracef("Loading user config from: %s", userConfigPath)
287-
userConfig, err = LoadUserConfig(userConfigPath)
288-
if err != nil {
289-
log.Printf("%s: %s", userConfigPath, err)
290-
}
291-
} else {
292-
p.Tracef("No user config found at: %s", userConfigPath)
293-
}
294-
295286
config.State.LockTimeout = cli.getLockTimeout()
296287
sta, err = state.Open(hermit.UserStateDir, config.State, cache)
297288
if err != nil {

0 commit comments

Comments
 (0)