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 1qdQ8Z-003Iys-VF for pgadmin-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 07:06:12 +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 1qdQ8Y-00HMNh-Oh for pgadmin-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 07:06:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdQ8Y-00HMNR-El for pgadmin-hackers@lists.postgresql.org; Tue, 05 Sep 2023 07:06:10 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qdQ8T-0038rd-J3 for pgadmin-hackers@postgresql.org; Tue, 05 Sep 2023 07:06:09 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-500d13a8fafso3793085e87.1 for ; Tue, 05 Sep 2023 00:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1693897563; x=1694502363; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=H7bDLzJuW5Hxu3Z1dwZztpJqK2wA7sfyXQD6dZTnEdA=; b=UG1t9yb5OzWsGg9PYC6dPJb2qLSQxqQrwV8QkKyG6JGWKTyWa1ovD9SRJinYQjl6xT Y6C3lE9rcfMTa5WgJ0MsQkvUCj6/6FxxsOGDds0td8yMkov/7CBq7X/PgZweWCJ4L+Lx Lwf5+r8PcYvQNLQYXxhC3WnIq86OxsWvd2J9RoOsqEz+soZbiCXYPexTxCLH5xbMDJ9Z Mf6Ll9hgNhlUkxe8Ra7BUkfmJ7EjzyR4V72uTRq+jDSLencMMv+Xr0l4n+TWwEgcR5/t aMR4PLocP5O7arA0xSoCdGYvCQf6kAlqslWFNpDLVNyXKmGcOr4ZTMs4zpnfTKlOjfBc FDmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693897563; x=1694502363; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H7bDLzJuW5Hxu3Z1dwZztpJqK2wA7sfyXQD6dZTnEdA=; b=dcgAsHGYLBw5UhEtn03qA3YV5+V2Dlgm6WhfdZRY7AxFBGYqIkOFuNZdDftnGlBGWm Za1Hbs8EB/rPMa3UrxBQlB3hJSVIGddEK7KTsosh/BOwf8glFqiPPv93urngqmpYUH5m WXG7TL8vO+LGnpkIWzkarEmMTwSM4sbTILMQSz+HFOKTBbCj2WlpVqHg5OV5Sz02r2lZ AfS4Lqu9gxf7RKipwP8dbWGM6znQsYb+5GBpq4LIwhhTmlNvgUZJy+Z6jWoXpqoRog2S KrmfEGZoyb0UNuBwS67ecIRVe0lj+5NRaot4DyOj9tuGP47cVhgWcTCTwUkRh2bue3jR SwKQ== X-Gm-Message-State: AOJu0YykDYQdlZH0STSaonTFCLKyXs21HwDs+qFBku/cOlAGb0rK8a/X vayVlri+DU0uHN2dTrb6qkI5p076SDLD2sSbkUPrqQ== X-Google-Smtp-Source: AGHT+IHEiBRNKeEqmX1cVk4YPv7BOClRv45s+2scPT+TTBfvwwQMltug9ZPfYX1Ry6j4MYKgwUxOxRab/JxYC1YyW5s= X-Received: by 2002:a05:6512:3a9:b0:500:bb99:69a5 with SMTP id v9-20020a05651203a900b00500bb9969a5mr7678686lfp.43.1693897563232; Tue, 05 Sep 2023 00:06:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Akshay Joshi Date: Tue, 5 Sep 2023 12:35:51 +0530 Message-ID: Subject: Re: #2483 - Add pgAdmin users via a CLI or script call To: Khushboo Vashi Cc: pgadmin-hackers Content-Type: multipart/alternative; boundary="0000000000008af302060497424b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008af302060497424b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Seems good to me. On Mon, Sep 4, 2023 at 5:20=E2=80=AFPM Khushboo Vashi < khushboo.vashi@enterprisedb.com> wrote: > 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 i= s > 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] =3D None, sqlite_p= ath: Optional[str] =3D None, replace: Optional[bool] =3D 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 > > > =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 example of reducing complexity: > > *ArgParse code:* > > if __name__ =3D=3D '__main__': >> # Configuration settings >> parser =3D argparse.ArgumentParser(description=3D'Setup the pgAdmin = config DB') > > > imp_group =3D parser.add_argument_group('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'replace', action=3D'stor= e_true', >> help=3D'replace server configurations', >> required=3DFalse) > > > imp_group.set_defaults(replace=3DFalse) >> > > args, extra =3D 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)) > > =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 > > *Equivalent Typer code:* > > @app.command() >> >> def load_servers(loadservers: 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/questions, do let me know. > > Thanks, > Khushboo > > > --0000000000008af302060497424b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Seems good to me.

On Mon, Sep 4, 2023 at 5:20=E2=80=AFPM Kh= ushboo Vashi <khushbo= o.vashi@enterprisedb.com> wrote:
H= ello hackers,

=
I am working on #2483 -=C2=A0Add pgAd= min 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 in= troduce 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] =3D None, sqlite_path: Optional= [str] =3D None, replace: = Optional[bool] =3D False):

The command will be like this:<=
/font>
python setup.py load-servers test.json
python 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 example of reducing comp= lexity:

=
ArgParse code:
if __name__ =3D=3D '__main__':
# Configurati= on settings
parser =3D argpars= e.ArgumentParser(description=3D= 'Setup the pgAdmin config DB')

imp_group =3D parser.add_argument_group('Load server config')
imp_group.add_argument('--load-servers', meta= var=3D"INPUT_FILE",
= help=3D'Load servers into the DB', required=3DFals= e)
imp_group.add_argu= ment('--replace', dest=3D'replace', action= =3D'store_true',<= br> help=3D'replace server configurations',
required=3DFalse)

imp_group.set_defaults(replace=3DFalse)

args, extra = =3D parser.parse_known_args()

# What to do?
if args.dump_servers is not None:
try:
dump_servers(args)
e= xcept 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
Equivalent Typer code:
@app.command()
def load_servers(loads=
ervers: str, user: Optional[str] =3D None, sqlite_path: Optional[str]=
 =3D None, replace: Optional[bool] =3D False):
.......
app =3D typer.Ty= per()
if __name__ =3D=3D &qu= ot;__main__":
ap= p()


If anyone has any suggestions/questions, do let me k= now.

Thanks,
Khushboo