lix/src/libutil
John Ericson 3d065192c0 Overhaul completions, redo #6693 (#8131)
As I complained in
https://github.com/NixOS/nix/pull/6784#issuecomment-1421777030 (a
comment on the wrong PR, sorry again!), #6693 introduced a second
completions mechanism to fix a bug. Having two completion mechanisms
isn't so nice.

As @thufschmitt also pointed out, it was a bummer to go from `FlakeRef`
to `std::string` when collecting flake refs. Now it is `FlakeRefs`
again.

The underlying issue that sought to work around was that completion of
arguments not at the end can still benefit from the information from
latter arguments.

To fix this better, we rip out that change and simply defer all
completion processing until after all the (regular, already-complete)
arguments have been passed.

In addition, I noticed the original completion logic used some global
variables. I do not like global variables, because even if they save
lines of code, they also obfuscate the architecture of the code.

I got rid of them  moved them to a new `RootArgs` class, which now has
`parseCmdline` instead of `Args`. The idea is that we have many argument
parsers from subcommands and what-not, but only one root args that owns
the other per actual parsing invocation. The state that was global is
now part of the root args instead.

This did, admittedly, add a bunch of new code. And I do feel bad about
that. So I went and added a lot of API docs to try to at least make the
current state of things clear to the next person.

--

This is needed for RFC 134 (tracking issue #7868). It was very hard to
modularize `Installable` parsing when there were two completion
arguments. I wouldn't go as far as to say it is *easy* now, but at least
it is less hard (and the completions test finally passed).

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Change-Id: If18cd5be78da4a70635e3fdcac6326dbfeea71a5
(cherry picked from commit 67eb37c1d0de28160cd25376e51d1ec1b1c8305b)
2024-03-25 15:30:36 +00:00
..
args Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
abstract-setting-to-json.hh Merge pull request #9299 from tfc/config-improvements 2024-03-04 05:36:42 +01:00
ansicolor.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
archive.cc libutil: make AutoCloseFD a better resource 2024-03-18 15:42:52 -06:00
archive.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
args.cc Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
args.hh Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
box_ptr.hh Add box_ptr: nonnull unique_ptr with value semantics 2024-03-11 01:04:52 -07:00
callback.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
canon-path.cc Backport SourcePath from the lazy-trees branch 2023-04-06 13:15:50 +02:00
canon-path.hh Merge remote-tracking branch 'upstream/master' into source-path 2023-04-17 11:41:50 +02:00
cgroup.cc Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
cgroup.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
chunked-vector.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
closure.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
comparator.hh Merge pull request #9582 from pennae/misc-opts 2024-03-04 07:32:31 +01:00
compression.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
compression.hh Rename and protect BufferedSink::write 2023-04-07 09:21:50 +02:00
compute-levels.cc Add x86_64 compute levels as additional system types 2021-02-22 09:11:15 +01:00
compute-levels.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
config-impl.hh Merge pull request #9299 from tfc/config-improvements 2024-03-04 05:36:42 +01:00
config.cc Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
config.hh Merge pull request #9233 from bouk/bouk/apply-config-inner 2024-03-04 07:11:25 +01:00
english.cc Unify and refactor value printing 2024-03-09 03:50:06 +01:00
english.hh Unify and refactor value printing 2024-03-09 03:50:06 +01:00
error.cc libutil: remove exception handling workingness check 2024-03-19 06:09:42 -06:00
error.hh libutil: remove exception handling workingness check 2024-03-19 06:09:42 -06:00
exit.cc :quit in the debugger should quit the whole program 2024-03-09 10:17:26 -07:00
exit.hh :quit in the debugger should quit the whole program 2024-03-09 10:17:26 -07:00
experimental-features.cc add automated usage mode to the repl 2024-03-11 14:14:43 -07:00
experimental-features.hh add automated usage mode to the repl 2024-03-11 14:14:43 -07:00
filesystem.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
finally.hh finally.hh: delete copy constructor which is a bad idea 2024-03-11 01:04:52 -07:00
fmt.hh Merge pull request #9925 from 9999years/fmt-cleanup 2024-03-09 07:00:13 -07:00
git.cc Fix the parsing of the sourcehut refs file 2022-05-04 14:38:59 +02:00
git.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
hash.cc Merge pull request #7732 from hercules-ci/make-initLibStore-viable-alternative 2023-04-17 08:04:41 -04:00
hash.hh Rename and protect BufferedSink::write 2023-04-07 09:21:50 +02:00
hilite.cc Fix incorrect comment in hiliteMatches 2022-06-05 20:30:18 +02:00
hilite.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
input-accessor.hh Merge pull request #9634 from 9999years/combine-abstract-pos-and-pos 2024-03-05 23:46:18 -07:00
json-impls.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
json-utils.cc Fix derivation load assertion errors 2023-08-05 01:34:30 +02:00
json-utils.hh fix: nlohmann::adl_serializer for std::optional (#9147) 2024-03-04 07:11:25 +01:00
local.mk Overhaul completions, redo #6693 (#8131) 2024-03-25 15:30:36 +00:00
logging.cc Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
logging.hh Merge pull request #9925 from 9999years/fmt-cleanup 2024-03-09 07:00:13 -07:00
lru-cache.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
meson.build build: optionally build and install with meson 2024-03-22 08:36:50 -06:00
monitor-fd.hh util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
namespaces.cc Simplify the PID namespace check: just try to mount /proc 2023-02-10 14:38:14 +01:00
namespaces.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
pool.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
position.cc match line endings used by parser and error reports 2024-03-18 16:12:46 +01:00
position.hh match line endings used by parser and error reports 2024-03-18 16:12:46 +01:00
ref.hh Merge pull request #9634 from 9999years/combine-abstract-pos-and-pos 2024-03-05 23:46:18 -07:00
references.cc Don't assume the type of string::size_type 2023-06-15 21:24:14 +02:00
references.hh Don't assume the type of string::size_type 2023-06-15 21:24:14 +02:00
regex-combinators.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
repair-flag.hh Merge pull request #9634 from 9999years/combine-abstract-pos-and-pos 2024-03-05 23:46:18 -07:00
serialise.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
serialise.hh Merge pull request #9798 from edolstra/remote-store-eof 2024-03-04 08:12:15 +01:00
signals.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
signals.hh util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
source-path.cc Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
source-path.hh Merge pull request #9985 from alois31/symlink-resolution 2024-03-07 00:43:51 -07:00
split.hh Delete hasPrefix and hasSuffix from the codebase 2024-03-17 20:17:19 -07:00
suggestions.cc Implement operator<< for Suggestions 2022-03-07 10:09:10 +01:00
suggestions.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
sync.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
tarfile.cc Merge pull request #9557 from bryanhonof/bryanhonof.fix-apple-double-shenanigans 2024-03-04 07:11:25 +01:00
tarfile.hh TarArchive: Remove a duplicate constant and increase the buffer size 2023-04-25 16:43:10 +02:00
thread-pool.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
thread-pool.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
topo-sort.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
types.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
url-parts.hh Merge pull request #9621 from blaggacao/fix/too-restrictive-branch-regex-master 2024-03-04 07:27:52 +01:00
url.cc libutil: fix double-encoding of URLs 2023-08-17 14:16:19 -07:00
url.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
util.cc libutil: don't memset 64k in drainFD 2024-03-23 22:17:46 +00:00
util.hh libutil: remove exception handling workingness check 2024-03-19 06:09:42 -06:00
variant-wrapper.hh Fixing #7479 2023-08-18 11:44:00 -04:00
xml-writer.cc xml-writer: Remove std aliases 2022-02-25 16:13:02 +01:00
xml-writer.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00