Fossil

Update of "branch/double-dash-flag"
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: b5450b8c3d9f6e52acdbd4ba768de7fb886093a9897fe7a334977852921bd066
Page Name:branch/double-dash-flag
Date: 2019-09-27 23:56:41
Original User: stephan
Mimetype:text/x-markdown
Parent: 1e7366c81c709791dfcbb48c9b53052f95d52e10736789b69b29970a87c9c708 (diff)
Next 9904cbb81d6a2999b59e5d9ec8df9935998fb5f64a7b5c865457e02ea6694f15
Content

Management Summary

The double-dash-flag branch aims to add support for the conventional interpretation of a -- flag: all arguments after the first instance of -- are to be treated as non-flag arguments (e.g. file/wiki/branch/whatever names).

This feature request is from: https://fossil-scm.org/forum/forumpost/64acc6b653

The implementation is not 100% compliant with POSIX/Unix conventions because it cannot be without Breaking Stuff, but it "should" be close enough to be useful/conventional for the contexts where using -- makes sense in Fossil. For example, uv add treats a filename of - as stdin by default (and has valid use cases enabled by that), and -- could be used to make uv add treat - as a filename (that's the original use case for which conventional -- support was proposed).

Compatibility vs. Historical Behaviour

Fossil's historical handling of -- is really weird: the first time find_option() encounters --, it removes that flag and stops processing arguments. Subsequent calls to find_option() then never see -- and thus treat all arguments as potential flags (even those after the prior position of --). Since that behaviour was never useful, and potentially confusing, it is unexpected that the changes made in this branch will break any historical usage of the CLI commands.

For example:

fossil foo -- -a -b -c

The current (trunk, as of this writing) interpretation of -a -b -c, because of the "one-time-swallowing" of --, depends on what order those flags are checked for via find_option(). It seems highly unlikely that anyone could have reliably depended on that, and therefore seems unlikely that this change will break anyone's scripts.

Commands which accept a filename as the value of a flag are unaffected by these changes, provided the flag comes before --:

fossil foo -R - -- -a -b -c

Would (both before and after this change) treat - as a repository file name, but this change will cause the subsequent -a -b -c flags to be interpreted as non-flags (it's then up to the foo command to deal with them).

This Implementation's Behaviour

  1. find_option() and its variants always stop looking for flags when they encounter --.
  2. verify_all_options() triggers a fatal error if -- is found in the argument list.
  3. verify_all_options2() consumes the first instance of -- and records the g.argv index where -- was found in g.argDashDashIndex, so that commands which need to can determine whether, e.g., an argument of - should be treated as an alias for stdin/stdout or as a literal filename (the latter only applies if -- precedes the - argument). The utility function get_dash_filename_arg() makes that particular use case trivial to implement.

It seems, after having migrated many of the commands, that it would be harmless/risk-free to eliminate verify_all_options2() and have verify_all_options() adopt that function's behaviour. That would make the -- flag a harmless no-op for commands which don't/can't make any special use of it.

(ONGOING) List of commands/subcommands extended to support --

(Please keep this list alphabetized by command/subcommand name.)

The Obligatory Exceptions