Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[cli] Make it optional to pass adminUser when only one account is configured

Neeraj Guptada3c6a78d46c
diff --git a/cli/cmd/admin.go b/cli/cmd/admin.go
index d46fcfbf71..fd22bc739b 100644
--- a/cli/cmd/admin.go
+++ b/cli/cmd/admin.go
@@ -94,12 +94,12 @@ func init() {
rootCmd.AddCommand(_adminCmd)
_ = _userDetailsCmd.MarkFlagRequired("admin-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)")
- _listUsers.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
- _disable2faCmd.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. ")
_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)")
// 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")
diff --git a/cli/pkg/admin_actions.go b/cli/pkg/admin_actions.go
index a5d1829737..7b9927c6a7 100644
--- a/cli/pkg/admin_actions.go
+++ b/cli/pkg/admin_actions.go
@@ -102,6 +102,9 @@ func (c *ClICtrl) buildAdminContext(ctx context.Context, adminEmail string) (con
if err != nil {
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
for _, a := range accounts {
if a.Email == adminEmail {
@@ -109,6 +112,14 @@ func (c *ClICtrl) buildAdminContext(ctx context.Context, adminEmail string) (con
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 {
return nil, fmt.Errorf("account not found for %s, use `account list` to list accounts", adminEmail)
}