[cli] Make it optional to pass adminUser when only one account is configured
This commit is contained in:
parent
324eeed1c5
commit
da3c6a78d4
|
@ -94,12 +94,12 @@ func init() {
|
||||||
rootCmd.AddCommand(_adminCmd)
|
rootCmd.AddCommand(_adminCmd)
|
||||||
_ = _userDetailsCmd.MarkFlagRequired("admin-user")
|
_ = _userDetailsCmd.MarkFlagRequired("admin-user")
|
||||||
_ = _userDetailsCmd.MarkFlagRequired("user")
|
_ = _userDetailsCmd.MarkFlagRequired("user")
|
||||||
_userDetailsCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
|
_userDetailsCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. ")
|
||||||
_userDetailsCmd.Flags().StringP("user", "u", "", "The email of the user to fetch details for. (required)")
|
_userDetailsCmd.Flags().StringP("user", "u", "", "The email of the user to fetch details for. (required)")
|
||||||
_listUsers.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
|
_listUsers.Flags().StringP("admin-user", "a", "", "The email of the admin user. ")
|
||||||
_disable2faCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
|
_disable2faCmd.Flags().StringP("admin-user", "a", "", "The email of the admin user. ")
|
||||||
_disable2faCmd.Flags().StringP("user", "u", "", "The email of the user to disable 2FA for. (required)")
|
_disable2faCmd.Flags().StringP("user", "u", "", "The email of the user to disable 2FA for. (required)")
|
||||||
_updateFreeUserStorage.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
|
_updateFreeUserStorage.Flags().StringP("admin-user", "a", "", "The email of the admin user.")
|
||||||
_updateFreeUserStorage.Flags().StringP("user", "u", "", "The email of the user to update subscription for. (required)")
|
_updateFreeUserStorage.Flags().StringP("user", "u", "", "The email of the user to update subscription for. (required)")
|
||||||
// add a flag with no value --no-limit
|
// add a flag with no value --no-limit
|
||||||
_updateFreeUserStorage.Flags().String("no-limit", "True", "When true, sets 100TB as storage limit, and expiry to current date + 100 years")
|
_updateFreeUserStorage.Flags().String("no-limit", "True", "When true, sets 100TB as storage limit, and expiry to current date + 100 years")
|
||||||
|
|
|
@ -102,6 +102,9 @@ func (c *ClICtrl) buildAdminContext(ctx context.Context, adminEmail string) (con
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(accounts) == 0 {
|
||||||
|
return nil, fmt.Errorf("no accounts found, use `account add` to add an account")
|
||||||
|
}
|
||||||
var acc *model.Account
|
var acc *model.Account
|
||||||
for _, a := range accounts {
|
for _, a := range accounts {
|
||||||
if a.Email == adminEmail {
|
if a.Email == adminEmail {
|
||||||
|
@ -109,6 +112,14 @@ func (c *ClICtrl) buildAdminContext(ctx context.Context, adminEmail string) (con
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (len(accounts) > 1) && (acc == nil) {
|
||||||
|
return nil, fmt.Errorf("multiple accounts found, specify the admin email using --admin-user")
|
||||||
|
}
|
||||||
|
if acc == nil && len(accounts) == 1 {
|
||||||
|
acc = &accounts[0]
|
||||||
|
fmt.Printf("Assuming %s as the Admin \n------------\n", acc.Email)
|
||||||
|
}
|
||||||
|
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
return nil, fmt.Errorf("account not found for %s, use `account list` to list accounts", adminEmail)
|
return nil, fmt.Errorf("account not found for %s, use `account list` to list accounts", adminEmail)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue