[issue33227] Cmd do_something only accepts one argument

2018-04-06 Thread Ned Deily

Ned Deily  added the comment:

Oz, I don't particularly like the idea of deprecating cmd but, realistically, 
Python development is almost entirely an unpaid, volunteer activity and we do 
not have enough resources to do everything we'd like to do.  So sometimes we 
need to make a tradeoff and this seems like it might be a good opportunity to 
make one that will benefit most people.  It's not my decision to make in 
isolation so I've sent a mail to the python-dev list asking other core 
developers and interested parties to comment on Issue33233.  So, let's keep 
this open until we resolve that issue and feel free to comment there.  Thanks 
again for your interest!

https://mail.python.org/pipermail/python-dev/2018-April/152653.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-06 Thread Oz Tiram

Oz Tiram  added the comment:

I am disappointed you want to deprecate CMD. I knew about cmd2 and some other 
alternatives, but I think their execive use of decorators isn't so comfortable. 
That is why I wrote my own module.

I'm also willing to adopt the module and add even more features.

--
status: pending -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-06 Thread Ned Deily

Ned Deily  added the comment:

The more I think about it, the more I feel it would be a disservice to our 
users to add piecemeal enhancements like this to the standard library cmd 
module at this point, when cmd is essentially unmaintained and there is already 
a superior alternative.  I have opened Issue33233 suggesting we at least add a 
See Also doc link to cmd2 and to consider potentially deprecating cmd in the 
standard library.  Again, thanks for the suggestion, Oz, but I would like to 
close this issue.

--
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-06 Thread Éric Araujo

Éric Araujo  added the comment:

I think using shlex unconditionally to parse lines sent to cmd.Cmd may not be 
ideal.

Cmd is very generic and there are many ways to parse lines into arguments:
- no parsing (think Python shells or remote command execution)
- shlex (makes sense for unix users, maybe not others)
- parse_ints as in your example (lexing + conversion)
- optparse (I read about a tool where the interactive command format was the 
same as the command-line arguments format, which makes is super easy to support 
all commands in a config file or “session replay” file!)
- many more.

Could the shlex parsing be in a subclass?  Or is it small enough to be in the 
docs?  If it’s not small, maybe the base Cmd class needs to be reworked to make 
it easier to hook into line parsing?

--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-05 Thread Ned Deily

Ned Deily  added the comment:

Thanks for your suggested enhancement to the cmd module.  cmd has been around a 
*long* time and, unfortunately, has received very little maintenance or 
enhancement attention for many years.  In the meantime, third-party 
replacements for cmd have arisen.  One of the most popular is cmd2, available 
from PyPI, which has also been around a long time and appears to be actively 
maintained.  In particular, it looks like cmd2 already offers robust parsing of 
arguments.  While enhancing the standard library cmd module sounds like it 
might be a good idea, in this particular case, you and other potential users of 
cmd might be better off using cmd2.  In any case, unless a core developer is 
interested in shepherding this change, your proposed change is likely to 
languish.

https://pypi.org/project/cmd2/
https://cmd2.readthedocs.io/en/latest/argument_processing.html

--
nosy: +ned.deily
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-05 Thread Oz Tiram

Change by Oz Tiram :


--
components: +Library (Lib)
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33227] Cmd do_something only accepts one argument

2018-04-05 Thread Oz Tiram

New submission from Oz Tiram :

Considering that I want to build an CLI interactive program using cmd.Cmd,
which has multiple functions that accept two or more arguments,
I always have to do parsing of arg inside my do_methods for example:

class Calc(cmd.Cmd):

do_add(self, arg):
   a, b = parse_ints(arg)
   return a+b

do_mult(self, arg):
   a, b = parse_ints(arg)
   return a*b

This is easy enough for a simple calculator. But for more logic I need to 
create more parse_type and explicitly call them at the top of each do_stuff.
Considering this I have created a patch for Cmd.cmd, that keeps the old 
functionality, but adds the ability to pass multiple arguments without having 
to parse them every time. 
  
The functionality is as follows:


class MyProg(cmd.Cmd):

do_simple(self, arg):
   print(arg)

do_greet(self, name="World")
   print("Hello %s" %s)

do_add(self, a, b):
   print(a+b)


Now in the cmd prompt:

(Cmd) simple foo
foo  
(Cmd) # keeps the old functionallity 
(Cmd) add 2 3
5
# add two properly add the values
(Cmd) add 2
# expects two arguments, so it will print the help for add
(Cmd) greet
Hello World
# does not complain because it has a default value
(Cmd) greet Guido
Hello Guido
(Cmd) greet name=Raymond
Hello Raymond
# works too

None of these example guess the type. It is simply handles as a string. but I 
am playing around with automatically detecting types of variables using 
function annotations in python 3.5 and later.

Also, although, not demonstrated here, one can also define:

def do_some_method_with_kwargs(self, arg1, arg2, **kwargs):
... do fancy stuff ...

(Cmd) some_method_with_kwargs foo bar kwargs='{"name": "John", "age"=35}'

kwargs is parsed to a dict (using json.loads) when escaped properly.
This is a bit esoteric, hence not shown here (but the patch patch includes it).
 
I was wondering if this kind of enhancement would be considered for this 
module? 
I will happily create a PR with tests and documentation explaining this 
enhanced functionality.

--
files: cmd.patch
keywords: patch
messages: 314968
nosy: Oz.Tiram
priority: normal
severity: normal
status: open
title: Cmd do_something only accepts one argument
Added file: https://bugs.python.org/file47520/cmd.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com