(self, remove, expand, group_name, user_name)
Add the user to the group.
Add the user to the group.
Add the user to the group .
def run(self, remove, expand, group_name, user_name):
        """Add the user to the group."""
        if not isinstance(group_name, six.text_type):
            group_name = codecs.decode(group_name, 'utf-8')

        group = Group.query.filter_by(name=group_name).first()

        # List all members of a group and then exit.
        if expand:
            for _user in group.users:
                print(_user.username)
            return

        if not isinstance(user_name, six.text_type):
            user_name = codecs.decode(user_name, 'utf-8')
        user = None
        if user_name:
            user = User.query.filter_by(username=user_name).first()

        # Add or remove user from group
        if remove and user:
            try:
                user.groups.remove(group)
                sys.stdout.write('{0:s} removed from group {1:s}\n'.format(
                    user_name, group_name))
                db_session.commit()
            except ValueError:
                sys.stdout.write('{0:s} is not a member of group {1:s}\n'.
                                 format(user_name, group_name))
        elif user:
            user.groups.append(group)
            try:
                db_session.commit()
                sys.stdout.write('{0:s} added to group {1:s}\n'.format(
                    user_name, group_name))
            except IntegrityError:
                sys.stdout.write('{0:s} is already a member of group {1:s}\n'.
                                 format(user_name, group_name))
def run ( self , remove , expand , group_name , user_name ) : if not isinstance ( group_name , six . text_type ) : group_name = codecs . decode ( group_name , 'utf-8' ) group = Group . query . filter_by ( name = group_name ) . first ( ) # List all members of a group and then exit. if expand : for _user in group . users : print ( _user . username ) return if not isinstance ( user_name , six . text_type ) : user_name = codecs . decode ( user_name , 'utf-8' ) user = None if user_name : user = User . query . filter_by ( username = user_name ) . first ( ) # Add or remove user from group if remove and user : try : user . groups . remove ( group ) sys . stdout . write ( '{0:s} removed from group {1:s}\n' . format ( user_name , group_name ) ) db_session . commit ( ) except ValueError : sys . stdout . write ( '{0:s} is not a member of group {1:s}\n' . format ( user_name , group_name ) ) elif user : user . groups . append ( group ) try : db_session . commit ( ) sys . stdout . write ( '{0:s} added to group {1:s}\n' . format ( user_name , group_name ) ) except IntegrityError : sys . stdout . write ( '{0:s} is already a member of group {1:s}\n' . format ( user_name , group_name ) )