I'd consider grouping similar functions under files (i.e. modules) and
import them.
For example:
import location_lib
@click.command()
@click.option('--delete')
@click.argument('location')
def location(delete, location):
if delete:
location_lib.delete(location)
location_lib.location(location)
Treat your main click script as the entrypoint to your various
functions/libraries. FYI, I did not test what I've written above, it's
purely an example going off the documentation.
You might also be interested in taking a skim through https://clig.dev/
which has some nice best practices around building CLIs.
On Thu, Jul 29, 2021 at 3:42 PM Eric Lease Morgan <[log in to unmask]> wrote:
> On Jul 29, 2021, at 12:46 PM, Eric Lease Morgan <[log in to unmask]> wrote:
>
> > So far, Click has been working for me:
> https://click.palletsprojects.com/en/8.0.x/
>
>
> My Click script is coming along quite nicely, but now I have a Python
> noobie question. My script is getting longer and longer with various
> definitions looking something like this:
>
> @click.command()
> def config() :
> # do cool stuff here
>
> @click.command()
> @click.argument( 'location' )
> def list( location ) :
> # do more cool stuff
>
> @click.command()
> @click.argument( 'carrel' )
> def harvest( carrel ) :
> # do even more cool stuff
>
> What is the technique I should use if I want to put each of these little
> functions into individual files? In the end, I'd like to have a whole set
> of little files where each one does a specific operation. I suppose I could
> create file full of functions, but then that file would be very long.
>
> --
> Eric "Sort Of Embarrassed" Morgan
>
--
Brian Wu
Email: [log in to unmask]
|