Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qd86T-002HRC-4f for pgadmin-hackers@arkaria.postgresql.org; Mon, 04 Sep 2023 11:50:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qd86R-00Am7U-80 for pgadmin-hackers@arkaria.postgresql.org; Mon, 04 Sep 2023 11:50:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qd86Q-00Am6o-Rl for pgadmin-hackers@lists.postgresql.org; Mon, 04 Sep 2023 11:50:46 +0000 Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qd86M-002ftq-AR for pgadmin-hackers@postgresql.org; Mon, 04 Sep 2023 11:50:44 +0000 Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-d74a012e613so1824017276.1 for ; Mon, 04 Sep 2023 04:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1693828241; x=1694433041; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Rqqa4VbFMMxiTupxpXbqraLidUY51mPya7Q8C+OlOtI=; b=Sq73y6rRiJuXmCqVIxz4r2bdmemu7RhLyKfgbhlEwcIqiJWYOkCsFYpILTlyxOZ4qQ CmM6+diJKuY/idtgns7L+k9MWyVtkcsx21NOgHaXxcxn6dR+Rf9jpbmMgDNcS8OcvAed rVnoAgvvmJ4kz+ZgQsMb3vYFaBiF7pVCaXXLcxTevnwgie9yv10gz4i0+TA4Nt2jR0Ma UcDHB9saO8tauVKrRfh7yhEXWcZXDXTIW0QRurSrRhffNzYCJX4GJoebDEwPkNTLAAU6 injrujrRYkGccMhQ3s86fZlsB70D6HyPsvYcwR2I5UcdSYVgPZeMKtHNrm7aJFB9V+O1 gxGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693828241; x=1694433041; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Rqqa4VbFMMxiTupxpXbqraLidUY51mPya7Q8C+OlOtI=; b=Ia8oQvCzL4KpG4soLJDx2ht5hu7x7SkFd/ft3BzZk5niJhgUneVM59sQMNTJ/prH/H OYKAtx8bE4D06JfDJ149NseWbE5udemcM+8MjjjIvhvj3KatU2hy8ggSmeDMb/waDgOs 1+LzWGiRzCGKMvm+nSi2Toy1O3BWcjSf9KdHJ+ByFFRVfCA1biqDthfo2Ld6kdlGWqPs IeT1IrCkGl/7JJTtI2rry261QVoEeUv/EXzA+trGUCZOZ4bm7xkdQp9CNGqRqGLixkdo aUQXPXsozhlVnOqZchN+yvKLbbjn0wo0uSN18gU4vQ/Ik7JMG0549oTVcpXd7UwHmkMJ Q58Q== X-Gm-Message-State: AOJu0YxM6lGwk98Nr38gDhhad9edz0na8lpXByYNMpcssL4iwHPQIl+O B/XcpXiDf59nllcRCEJHlCctMdVVs55badDGRwkjaUmQo7vj4h0b99Y= X-Google-Smtp-Source: AGHT+IHgak2GL7DXMrMUXq4vOIm3joAUQz3pLdv+UwdJob/HG+L2zB6FhmeLi8rUV07jLFeA1e3tj6Pchm+fXtRKVAg= X-Received: by 2002:a25:cfd8:0:b0:d78:3b67:ef3 with SMTP id f207-20020a25cfd8000000b00d783b670ef3mr13603531ybg.12.1693828240146; Mon, 04 Sep 2023 04:50:40 -0700 (PDT) MIME-Version: 1.0 From: Khushboo Vashi Date: Mon, 4 Sep 2023 17:20:28 +0530 Message-ID: Subject: #2483 - Add pgAdmin users via a CLI or script call To: pgadmin-hackers Content-Type: multipart/alternative; boundary="0000000000009095ad0604871e7f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009095ad0604871e7f Content-Type: text/plain; charset="UTF-8" Hello hackers, I am working on #2483 - Add pgAdmin users via a CLI or script call. As we want a consistent and centralised CLI, I suggest replacing Argparse with the Typer package. The main advantage of the Typer is that it decreases the complexity and is built upon CLICK, the most used library for Python CLI. We will use the setup.py file for all the CLI modules; we can introduce one function per CLI feature (per command) as described below. So, the below line will cover all the combinations of Load server functionality. @app.command() def load_servers(loadservers: str, user: Optional[str] = None, sqlite_path: Optional[str] = None, replace: Optional[bool] = False): The command will be like this: python setup.py load-servers test.json python setup.py load-servers test.json --replace python setup.py load-servers a.json --user 'test@gmail.com' --replace ====================================================================== An example of reducing complexity: *ArgParse code:* if __name__ == '__main__': > # Configuration settings > parser = argparse.ArgumentParser(description='Setup the pgAdmin config DB') imp_group = parser.add_argument_group('Load server config') > imp_group.add_argument('--load-servers', metavar="INPUT_FILE", > help='Load servers into the DB', required=False) > imp_group.add_argument('--replace', dest='replace', action='store_true', > help='replace server configurations', > required=False) imp_group.set_defaults(replace=False) > args, extra = parser.parse_known_args() # What to do? > if args.dump_servers is not None: > try: > dump_servers(args) > except Exception as e: > print(str(e)) ====================================================================== *Equivalent Typer code:* @app.command() > > def load_servers(loadservers: str, user: Optional[str] = None, sqlite_path: Optional[str] = None, replace: Optional[bool] = False): > > ....... > app = typer.Typer() > if __name__ == "__main__": > app() If anyone has any suggestions/questions, do let me know. Thanks, Khushboo --0000000000009095ad0604871e7f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello hackers,
I am working on #2483 -=C2=A0Add pgAdmin users via a CLI or s= cript call.
As we want a = consistent and centralised CLI, I suggest replacing Argparse with the Typer package.
= The main advantage of the Typer is that it= decreases the complexity and is built upon CLICK, the most used library fo= r Python CLI.

=
We will use the setup.py file f= or all the CLI modules; we can introduce one function per CLI feature (per = command) as described below.
So, the below line will cover all the combinations of Load server funct= ionality.
@app.command(=
)
def load_servers(loadservers: str, user: Optional[str] =3D None, sqlite_path: Optional[str] =3D None, replace: Optional[= bool] =3D False):
<= /pre>

<= /font>

p= ython setup.py load-servers test.json --replace=C2=A0 =C2=A0 =C2=A0=C2=A0
python setup.py load-servers a.json --user 'test@gmail.com' --replace=C2=A0 =C2=A0 =C2=A0= =C2=A0

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
An exampl= e of reducing complexity:

ArgPa= rse code:
if __name__ =3D=3D <= span style=3D"color:rgb(6,125,23)">'__main__':
# Configuration settings
= parser =3D argparse.ArgumentParser(description=3D'Setup t= he pgAdmin config DB')

imp_group =3D parser.add_argument_group(<= span style=3D"color:rgb(6,125,23)">'Load server config')
= imp_group.add_argument('--load-servers', metavar=3D"INPUT_FILE",
= help= =3D'Load servers into the DB', required=3DFalse)
imp_group.add_argument('= --replace', dest=3D<= span style=3D"color:rgb(6,125,23)">'replace', action=3D= 'store_true',
= help=3D= 'replace server configurations'= ,
= required=3DFalse)

imp_group.set_defaults(replace=3DFal= se)

args, extra =3D parser.parse_known_args()
# What to do?
if args.dum= p_servers is not None:
try:
dump_= servers(args)
except Exception as e:
= print(str(e))
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
Equivalen=
t Typer code:
@app.command()
=
def load_servers(loadserv=
ers: str, user: Optional[str] =3D =
None, sqlite_path: Optional[str] =3D None, replace: Optional[bool] =3D False):
.......
app =3D typer.Typer= ()
if __name__ =3D=3D "__main__":
app()


If anyone has any suggestions/quest= ions, do let me know.
Thanks,
Khushboo
=C2=A0
--0000000000009095ad0604871e7f--