andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.58k stars 179 forks source link

Change optparse to argparse #249

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

I cherry-pick the changes about converting optparse to argparse for convenience of review. Thanks.

andreafrancia commented 1 year ago

There are some failing tests. Please make them pass. To run tests on you computer use pytest.

Freed-Wu commented 1 year ago

It seems some test maybe can be changed because optparse and argparse has different behaviours, such as files, argparse will return

❯ ./trash-put
usage: trash-put [OPTION]... FILE...
trash-put: error: the following arguments are required: files

And the error seem that cannot be changed.

Freed-Wu commented 1 year ago

Now pytest has no error in my PC.

Freed-Wu commented 1 year ago

Now

❯ ./trash-put
usage: trash-put [OPTION]... FILE...
Please specify the files to trash.
Freed-Wu commented 1 year ago

Okay.

Freed-Wu commented 1 year ago

python2 cannot support file for print?

E       print("usage: ", file=sys.stderr, end="")
E                            ^
E   SyntaxError: invalid syntax
Freed-Wu commented 1 year ago

How about

            sys.stdout = sys.stderr
            parser.print_usage()
            print("Please specify the files to trash.")
            sys.stdout = sys.__stdout__
andreafrancia commented 1 year ago

python2 cannot support file for print?

E       print("usage: ", file=sys.stderr, end="")
E                            ^
E   SyntaxError: invalid syntax

You need to put from __future__ import print_function at the beginning of python file. See https://stackoverflow.com/a/9316160/36131

Freed-Wu commented 1 year ago

You need to put from future import print_function at the beginning of python file.

OKay.

andreafrancia commented 1 year ago

Don't rebase and/or squash every time you change something. Simply add a new commit. In this way it would be simpler reviewing the latest changes. When all works well and it is ready you can rebase and squash all the commits you want.

Freed-Wu commented 1 year ago

Okay.

Freed-Wu commented 1 year ago

Now pytest for python3/python2 all can work.

And the get_option_parser is renamed to make_parser. It maybe confuses reviewer. I am sorry. :cry: The code has many pathced_print/patched_error/..., I guess its aim is compatibility of python2? So I keep them.

Freed-Wu commented 1 year ago

Ok, now both pytest and scripts/test-sdist can work for python 2 and 3.