Proposal: django CMS commands refactoring

34 views
Skip to first unread message

Iacopo Spalletti

unread,
Nov 24, 2015, 4:46:37 PM11/24/15
to Django Cms-Developers
Now that the awesome 3.2 is out, it's time to draw our plans for 3.3 :)

My first proposal is to refactor the management commands: currently they
have inconsistent code style and interface (e.g.: options/arguments
confusion)
We can refactor them to use the new argparse interface of django
commands (optparse will be dropped in 1.10 anyway), provide a better
help support.
At this stage does not involve any functional change

Example :

from:

manage.py cms copy_lang it en

to:

manage.py cms copy-lang --from-lang=it --to-lang=en

See relevant issue: https://github.com/divio/django-cms/issues/4679

--
Cheers

Iacopo Spalletti

Jonas Obrist

unread,
Nov 24, 2015, 8:52:03 PM11/24/15
to django-cms...@googlegroups.com
Argparse supports subcommands (which are pretty neat), as well as positional (named) arguments, so no need to switch to --from-lang etc. Usually -/-- arguments are considered optional, but in your example, both from lang and to lang are required, so keeping it `manage.py cms copy-lang it en` makes more sense to me and is fully supported by argparse.



--
Cheers

Iacopo Spalletti

--
Message URL: https://groups.google.com/d/msg/django-cms-developers/topic-id/message-id
Unsubscribe: send a message to django-cms-devel...@googlegroups.com
--- You received this message because you are subscribed to the Google Groups "django CMS developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-cms-devel...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-cms-developers/5654DABA.6040500%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Iacopo Spalletti

unread,
Nov 25, 2015, 10:17:14 AM11/25/15
to django-cms...@googlegroups.com
Il 25/11/2015 02:52, Jonas Obrist ha scritto:
> Argparse supports subcommands (which are pretty neat), as well as
> positional (named) arguments, so no need to switch to --from-lang etc.
> Usually -/-- arguments are considered optional, but in your example,
> both from lang and to lang are required, so keeping it `manage.py cms
> copy-lang it en` makes more sense to me and is fully supported by argparse.
>
I'll look into subcommands implementation in argparse, thanks for
pointing me to it.

My itch is about replacing current sparse implementation of the commands
with a more uniform one and one which provides sensible help text etc,
the implementation details are left to the discussion :)

I'll post updates here when I have a first draft ready.

> On Wed, Nov 25, 2015 at 6:46 AM, Iacopo Spalletti
> <iacopo.s...@gmail.com <mailto:iacopo.s...@gmail.com>> wrote:
>
> Now that the awesome 3.2 is out, it's time to draw our plans for 3.3 :)
>
> My first proposal is to refactor the management commands: currently
> they have inconsistent code style and interface (e.g.:
> options/arguments confusion)
> We can refactor them to use the new argparse interface of django
> commands (optparse will be dropped in 1.10 anyway), provide a better
> help support.
> At this stage does not involve any functional change
>
> Example :
>
> from:
>
> manage.py cms copy_lang it en
>
> to:
>
> manage.py cms copy-lang --from-lang=it --to-lang=en
>
> See relevant issue: https://github.com/divio/django-cms/issues/4679
>
> --
> Cheers
>
> Iacopo Spalletti
>
> --
> Message URL:
> https://groups.google.com/d/msg/django-cms-developers/topic-id/message-id
> Unsubscribe: send a message to
> django-cms-devel...@googlegroups.com
> <mailto:django-cms-developers%2Bunsu...@googlegroups.com>
> --- You received this message because you are subscribed to the
> Google Groups "django CMS developers" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-cms-devel...@googlegroups.com
> <mailto:django-cms-developers%2Bunsu...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-cms-developers/5654DABA.6040500%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Message URL:
> https://groups.google.com/d/msg/django-cms-developers/topic-id/message-id
> Unsubscribe: send a message to
> django-cms-devel...@googlegroups.com
> ---
> You received this message because you are subscribed to the Google
> Groups "django CMS developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-cms-devel...@googlegroups.com
> <mailto:django-cms-devel...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-cms-developers/CAMS%3DEL11UfTvhBQf-C83zgWjLgcm5Nret07ex4_1Rr2kqJ0OtQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-cms-developers/CAMS%3DEL11UfTvhBQf-C83zgWjLgcm5Nret07ex4_1Rr2kqJ0OtQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
Cheers

Iacopo Spalletti

Iacopo Spalletti

unread,
Jan 23, 2016, 5:20:38 AM1/23/16
to django-cms...@googlegroups.com
On 25/11/2015 02:52, Jonas Obrist wrote:
> Argparse supports subcommands (which are pretty neat), as well as
> positional (named) arguments, so no need to switch to --from-lang etc.
> Usually -/-- arguments are considered optional, but in your example,
> both from lang and to lang are required, so keeping it `manage.py cms
> copy-lang it en` makes more sense to me and is fully supported by argparse.
>

I like -- arguments as they are self-documenting and less error prone
than positional arguments
Just to start discussion, I anyway opened this WiP PR
https://github.com/divio/django-cms/pull/4947 with the initial work of
basing commands on argparse (with the use of argparse subcommands too)
Any comment / vote on -- vs. positional arguments is welcome

--
Iacopo Spalletti

Nephila s.a.s. - Firenze
Telefono: +39 055 5357189
Assistenza Tecnica: +39 055 3985730
http://nephila.it

signature.asc
Reply all
Reply to author
Forward
0 new messages