-
-
Notifications
You must be signed in to change notification settings - Fork 2
command line option parsing #21
Comments
Comment by @williamstein created at 2007-01-13 01:56:18 no -- you can't combine command line options like that. this isn't a bug |
Comment by @williamstein created at 2007-01-13 01:56:18 Changing type from defect to enhancement. |
Comment by mabshoff created at 2007-09-11 02:11:39 This should be fixable, but the long term goal is to do a proper rewrite of the command line options. Cheers, Michael |
Comment by gfurnish created at 2008-03-16 07:59:18 Changing assignee from somebody to gfurnish. |
Comment by gfurnish created at 2008-03-16 07:59:18 Changing status from new to assigned. |
Comment by gfurnish created at 2008-04-04 19:55:55 Changing component from basic arithmetic to interfaces. |
Comment by mabshoff created at 2008-09-24 02:59:36 See also #180 for a bunch of related failures due to the option parsing being dumb :o Cheers, Michael |
Comment by mabshoff created at 2008-09-24 02:59:36 Changing status from assigned to new. |
Comment by mabshoff created at 2008-09-24 02:59:36 Changing assignee from gfurnish to mabshoff. |
Comment by mabshoff created at 2008-09-24 02:59:46 Changing status from new to assigned. |
Comment by kcrisman created at 2009-12-30 05:15:23 Note that sage -bn now builds, then does notebook, though of course it doesn't fix the issue here. |
Comment by jhpalmieri created at 2010-03-19 15:41:48 the file SAGE_ROOT/makefile |
Attachment makefile by jhpalmieri created at 2010-03-19 15:41:55 |
Attachment makefile.diff by jhpalmieri created at 2010-03-19 15:42:11 extcode repo |
Attachment trac_21-extcode.patch by jhpalmieri created at 2010-03-19 15:42:32 sagenb repo |
Attachment trac_21-sagenb.patch by jhpalmieri created at 2010-03-19 15:50:37 Here are patches. After applying "trac_21-scripts.patch", you may need to make "SAGE_ROOT/local/bin/sage-sage.py" executable. The build process works for me with these patches. For the standard packages, the third line in
should be changed to "Maybe run 'sage --sh'?", but this doesn't affect the functioning of the packages, and otherwise, they don't need changing. I haven't looked at optional packages. This approaches uses Python's optparse to parse command-line options. If someone wants to write a version using shflags or some other package, go ahead. I propose the following approach, whether using these patches or other ones:
Running "sage" (with no arguments) would not trigger this message. (Perhaps we could only turn this on in prerelease (alpha and rc) versions? Alternatively, a change like this could go with the version 5.0 release.)
perhaps with no easy way of disabling this message while using old-style options.
See sage-devel for some discussion. |
Comment by jhpalmieri created at 2010-03-19 15:50:37 Changing status from new to needs_review. |
Comment by jhpalmieri created at 2010-03-19 15:50:47 Changing priority from minor to critical. |
Comment by jhpalmieri created at 2010-03-19 20:25:24 I've marked this as "needs review", but it might need work. In the previously cited thread from sage-devel, there was the following suggestion:
This is to speed up access to these programs: do a check like this in a shell script, and then pass the rest of the arguments to Python's optparse using the script included in this patch, or one like it. Then you avoid the slight delay involved in starting up Python if you want to run "gp". It would be nice to have a shell script which had a list of strings "gp", "gap", etc., checked to see if the first(?) argument was "--STR" for STR in this list, and if so, run the appropriate program from SAGE_LOCAL/lib, passing the rest of the line as arguments. Having one list containing all of these strings would make it easy to customize. |
Attachment sage by jhpalmieri created at 2010-03-19 21:15:39 the file SAGE_ROOT/sage |
Attachment sage.diff by jhpalmieri created at 2010-03-19 21:22:45 Replying to [comment:10 jhpalmieri]:
Okay, here's a new version which does this: it adds a file sage-sage-quickstart which gets run first, implementing the above idea. Then if SAGE_NEW_OPTIONS is nonempty, it calls sage-sage.py, the Python/optparse version with GNU/Posix standard command-line options. Otherwise, it calls the old parser sage-sage. For the record, the commands in sage-sage-quickstart are: axiom, ecl/lisp, gap, gp, hg, ipython, maxima, mwrank, python, R, singular. Are any others particularly sensitive to startup times? (Using python adds something less than .1 second on my two-year old iMac, so we're not talking about a lot of time, in any case.) |
Comment by ohanar created at 2013-01-25 02:33:20 Replying to [comment:45 kini]:
Are you saying that a configuration file should store the current environment? And that anytime it is changed (such as if the root directory of sage is moved) that this should be updated?
Also
For one of two reasons:
|
Comment by kini created at 2013-01-25 07:10:02 Replying to [comment:46 ohanar]:
It should store the current startup environment. It would change if the root directory of Sage is moved, for example, yes. But if a user decided to change an environment variable in a Sage session with
Oh, right, of course. So then yes, |
Comment by jdemeyer created at 2013-01-25 07:35:11 Replying to [comment:45 kini]:
Of course it's bad design to have two-pass argument parsing, but it would be so nice to keep
|
Comment by kcrisman created at 2014-11-20 13:33:25 The command line interface continues to evolve; can someone (who cares) give a summary of what still would be needed? comment:24 still hasn't been resolved, and comment:33 (as well as quick, non-Python-starting, use of |
Comment by jdemeyer created at 2015-06-23 13:45:35 Changing component from interfaces to user interface. |
Comment by embray created at 2017-06-01 14:55:00 Still reading up on this ticket, and don't have any comments to add yet to the existing discussion. But one question I have in general: Is anyone opposed at all to the idea of creating a new sub-command based interface, more like git, than the slightly unusual interface that uses single-character flags for subcommands? E.g. replace |
Comment by jhpalmieri created at 2017-06-01 17:32:59 William Stein and I were just talking about this idea yesterday. Something like this?
Maybe some of these can be removed. Maybe some can be consolidated: do we need separate commands for gap, gp, maxima, ecl, R, etc., or can they be combined under a single command, like "sage run "? There is endless bikeshedding available. |
Comment by embray created at 2017-06-02 08:22:20 Yes, something quite like that. And I was thinking of writing up some kind of declarative list(s) of subcommands. In particular I was thinking two separate lists:
Although somewhat redundant, because it's common I would also have I might also hide more of the development-specific commands ( |
Comment by embray created at 2017-06-02 08:23:08 (I should add, that's a very nice mock-up of what such an interface would look like, so thank you for that.) |
Comment by jdemeyer created at 2017-06-02 13:01:28 Replying to [comment:55 embray]:
What about |
Comment by jdemeyer created at 2017-06-02 13:12:10 We should also think to what extent the build system should be exposed under the
and
This is all for historical and accidental reasons, but this ticket should clean that up too. |
Comment by jdemeyer created at 2017-06-02 13:13:22 Needless to say, many people don't even know the subtle differences between the above commands. |
Comment by embray created at 2017-06-06 09:42:41 Replying to [comment:59 jdemeyer]:
I was actually thinking of allowing subcommands to be chained, like in |
Comment by mkoeppe created at 2020-08-11 19:29:26 Strong -1 "wontfix" for the idea of making an incompatible change toward using "subcommands" after 14 years of the existence of the |
Comment by embray created at 2020-08-31 15:42:10 I think the current interface of the |
Comment by @williamstein created at 2020-08-31 17:58:19 +1 from me to changing the sage script to support subcommands, especially if we can somehow do it in a way that preserves compatibility with the current parsing. I wonder to what extent the following is possible:
Or something else, e.g,. if you do "sage [explicit list of subcommands]" uses the subcommand approach; otherwise, fall back to the current parser. I wrote at least the first version of the current sage command line parser, and frankly I didn't know what I was doing at the time, and just sort of stupidly copied random bits and pieces of design from programs I had used. Using python's subcommands support is a lot more systematic, and can also result in very nice modular code. |
Comment by embray created at 2020-09-01 13:32:32 Since all of the sage script's current "subcommands" (e.g. |
Comment by embray created at 2020-09-01 13:37:14 Replying to [comment:68 was]:
I might still just write it as a shell script. Reason being, based on my experience implementing CLIs in Python, it tends to be much much slower to run a single command. At the very least I would do this for the top-level |
Comment by @williamstein created at 2020-09-01 13:39:59
+1 I should have just said "in my experience, structuring command line parsing code as subcommands (implemented in any language) can result in very nice modular code." |
Comment by mkoeppe created at 2020-09-03 02:52:21 Changing priority from critical to minor. |
Comment by nbruin created at 2020-09-04 16:17:04 Replying to [comment:68 was]:
One very frustrating part of subcommands is the failure of standard tab-completion to work with it: |
Comment by jhpalmieri created at 2020-09-04 16:27:21 Replying to [comment:73 nbruin]:
The question so far has been (for example) |
Comment by nbruin created at 2020-09-04 16:48:07 Replying to [comment:74 jhpalmieri]:
From a tab-completion point of view that would make sense, yes. (that, or learn how to extend the tab completion patterns). For this particular example, I'd use The traditional reason for having dashes in front of options/subcommands is to remove ambiguity from Extrapolating from that, I think that using subcommands for the |
Comment by mkoeppe created at 2020-09-04 17:48:39 Replying to [comment:75 nbruin]:
I fully agree. |
Comment by kini created at 2020-09-04 18:00:40 Replying to [comment:75 nbruin]:
FWIW, there are tools which can do this for you if your command line subcommands and options are all handled by argparse (rather than e.g. a top level bash script that calls out to python programs that use argparse for each subcommand, as embray suggested). argcomplete will dynamically provide on-the-fly completion candidates by actually running the argument parsing logic from the shtab also runs the argument parsing logic from the If you use a shell other than bash, it may be harder. zsh, at least, is supported by shtab and to some extent argcomplete as well. I suggest that |
Issue created by migration from Trac.
Original creator: @williamstein
Original creation time: 2006-09-12 23:21:18
Assignee: somebody
CC: kini saraedum iandrus
We should improve and/or modernize and/or revise Sage's command-line parsing.
Two ideas, which could be debated endlessly and could also be implemented independently of each other:
sage --package ...
would be changed tosage package ...
, etc. (comment:56 and comment:57 list some possibilities)(changed by jhpalmieri at 2020-08-11 17:35:51)
The text was updated successfully, but these errors were encountered: