public inbox for [email protected]  
help / color / mirror / Atom feed
#2483 - Add pgAdmin users via a CLI or script call
2+ messages / 2 participants
[nested] [flat]

* #2483 - Add pgAdmin users via a CLI or script call
@ 2023-09-04 11:50  Khushboo Vashi <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Khushboo Vashi @ 2023-09-04 11:50 UTC (permalink / raw)
  To: pgadmin-hackers

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 <https://pypi.org/project/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 '[email protected]' --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


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: #2483 - Add pgAdmin users via a CLI or script call
@ 2023-09-05 07:05  Akshay Joshi <[email protected]>
  parent: Khushboo Vashi <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Akshay Joshi @ 2023-09-05 07:05 UTC (permalink / raw)
  To: Khushboo Vashi <[email protected]>; +Cc: pgadmin-hackers

Seems good to me.

On Mon, Sep 4, 2023 at 5:20 PM Khushboo Vashi <
[email protected]> 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 <https://pypi.org/project/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 '[email protected]' --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
>
>
>


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-09-05 07:05 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04 11:50 #2483 - Add pgAdmin users via a CLI or script call Khushboo Vashi <[email protected]>
2023-09-05 07:05 ` Akshay Joshi <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox