Enable multi-account migration
This commit is contained in:
parent
68e30beac4
commit
d2ff55737c
3 changed files with 17 additions and 11 deletions
|
|
@ -56,13 +56,12 @@ func mainRun() exitCode {
|
|||
|
||||
ctx := context.Background()
|
||||
|
||||
// cfg, err := cmdFactory.Config()
|
||||
// if err != nil {
|
||||
// fmt.Fprintf(stderr, "failed to load configuration to attempt migration: %s\n", err)
|
||||
// }
|
||||
// if err := cfg.MigrateMultiAccount(); err != nil {
|
||||
// fmt.Fprintf(stderr, "failed to migrate configuration: %s\n", err)
|
||||
// }
|
||||
if cfg, err := cmdFactory.Config(); err == nil {
|
||||
if err := cfg.MigrateMultiAccount(); err != nil {
|
||||
fmt.Fprintf(stderr, "failed to migrate configuration: %s\n", err)
|
||||
return exitError
|
||||
}
|
||||
}
|
||||
|
||||
updateCtx, updateCancel := context.WithCancel(ctx)
|
||||
defer updateCancel()
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@ func Migrate(c *ghConfig.Config, m Migration) error {
|
|||
// It is expected initially that there is no version key because we don't
|
||||
// have one to begin with, so an error is expected.
|
||||
version, _ := c.Get([]string{versionKey})
|
||||
|
||||
// If migration has already occured then do not attempt to migrate again.
|
||||
if m.PostVersion() == version {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If migration is incompatible with current version then return an error.
|
||||
if m.PreVersion() != version {
|
||||
return fmt.Errorf("failed to migrate as %q pre migration version did not match config version %q", m.PreVersion(), version)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,13 +103,13 @@ func (m MultiAccount) Do(c *config.Config) error {
|
|||
return CowardlyRefusalError{fmt.Errorf("couldn't get user name for %q: %w", hostname, err)}
|
||||
}
|
||||
|
||||
if err := migrateToken(hostname, username, token, inKeyring); err != nil {
|
||||
return CowardlyRefusalError{fmt.Errorf("couldn't not migrate oauth token for %q: %w", hostname, err)}
|
||||
}
|
||||
|
||||
if err := migrateConfig(c, hostname, username); err != nil {
|
||||
return CowardlyRefusalError{fmt.Errorf("couldn't not migrate config for %q: %w", hostname, err)}
|
||||
}
|
||||
|
||||
if err := migrateToken(hostname, username, token, inKeyring); err != nil {
|
||||
return CowardlyRefusalError{fmt.Errorf("couldn't not migrate oauth token for %q: %w", hostname, err)}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue