def _process_role_options( ctx, password, password_from_stdin, allow_empty=False ): if password is None and password_from_stdin: password = True if password is not None: if password: if password_from_stdin: password_value = ql(sys.stdin.readline().strip('\r\n')) elif sys.stdin.isatty(): password_value = ql(click.prompt( 'Password', hide_input=True, confirmation_prompt=True, type=str, )) else: raise click.UsageError( 'input is not a TTY, please use --password-from-stdin ' 'to provide the password value' ) else: password_value = '{}' else: password_value = None alters = [] if password_value is not None: alters.append(f'SET password := {password_value}') if not alters: if allow_empty: return alters raise click.UsageError( 'please specify an attribute to alter', ctx=ctx, ) return alters
def set(ctx, parameter: str, value): cfg_obj_name, cfg_type, cfg_card = _process_configure_scalar( ctx, parameter, []) if cfg_card == 'ONE': if len(value) > 1: raise click.ClickException('too many values', ctx=ctx) value = value[0] val_expr = ql(value) else: val_expr = f'{{{", ".join(ql(v) for v in value)}}}' # Canonicalize the values by casting them. vals = ctx.obj['conn'].fetchall(f''' SELECT <str><{cfg_type.name}>{val_expr} ''') args = [] for val in vals: if cfg_type.is_numeric or cfg_type.is_bool: args.append(val) elif cfg_type.is_str: args.append(ql(val)) else: raise click.ClickException( f'cannot set {parameter}: it is not a string, numeric or bool' ) args_list = ', '.join(args) args_expr = f'{{{args_list}}}' qry = textwrap.dedent(f''' CONFIGURE SYSTEM SET {cfg_obj_name} := {args_expr} ''') try: ctx.obj['conn'].execute(qry) except edgedb.EdgeDBError as e: raise click.ClickException(str(e)) from e else: click.echo(ctx.obj['conn']._get_last_status())