aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/args.cc
AgeCommit message (Collapse)Author
2024-05-31libutil: fix args assert being thrown on Darwin in nix-eval-jobsJade Lovelace
This is because a dynamic_cast<nix::RootArgs *> of a (n-e-j) MyArgs returns nullptr even though MyArgs has virtual nix::RootArgs as a parent. class MyArgs : virtual public nix::MixEvalArgs, virtual public nix::MixCommonArgs, virtual nix::RootArgs { ... }; So this should work right?? But it does not. We found out that it's caused by -fvisibility=hidden in n-e-j, but honestly this code was bad anyway. The trivial solution is to simply stop relying on RTTI working properly here, which is probably better OO architecture anyway. However, I am not 100% confident *this* is sound, since we have this horrible hierarchy: Args (defines getRoot) / | \ RootArgs MixCommonArgs MixEvalArgs (overrides) I am not confident that this is guaranteed to resolve from Args always in the case of this override. Assertion failed: (res), function getRoot, file src/libutil/args.cc, line 67. 6MyArgsProcess 60503 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert frame #4: 0x0000000100b1a41c liblixutil.dylib`nix::Args::processArgs(std::__1::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, bool) [inlined] nix::Args::getRoot(this=0x00000001000d0688) at args.cc:67:5 [opt] 64 std::cout << typeid(*p).name(); 65 66 auto * res = dynamic_cast<RootArgs *>(p); -> 67 assert(res); 68 return *res; 69 } 70 Target 0: (nix-eval-jobs) stopped. (lldb) p this (MyArgs *) 0x00000001000d0688 (lldb) p *this (nix::Args) { longFlags = size=180 { ... } shortFlags = size=4 { ... } expectedArgs = size=1 { ... } processedArgs = size=0 {} hiddenCategories = size=1 { [0] = "Options to override configuration settings" } parent = nullptr } We also found that if we did this: class [[gnu::visibility("default")]] RootArgs : virtual public Args it would work properly (???!). This is of course, very strange, because objdump -Ct output on liblixexpr.dylib is identical both with and without it. Possibly related: https://www.qt.io/blog/quality-assurance/one-way-dynamic_cast-across-library-boundaries-can-fail-and-how-to-fix-it Fixes: https://git.lix.systems/lix-project/nix-eval-jobs/issues/2 Change-Id: I6b9ed968ed56420a9c4d2dffd18999d78c2761bd
2024-05-30libutil/args: warn on unknown settings after parsing all flagsCole Helbling
Upstream change: https://github.com/NixOS/nix/pull/10701 Change-Id: Icf271df57ec529dd8c64667d1ef9f6dbf02d33d3
2024-05-29util.hh: Delete remaining file and clean up headersTom Hubrecht
Change-Id: Ic1f68e6af658e94ef7922841dd3ad4c69551ef56
2024-05-28util.{hh,cc}: Split out environment-variables.{hh,cc}Tom Hubrecht
Change-Id: Icff0aa33fda5147bd5dbe256a0b9d6a6c8a2c3f6
2024-03-27HOT SALE: 15% off your build times!Jade Lovelace
This was achieved by running maintainers/buildtime_report.sh on the build directory of a meson build, then asking "why the heck is json eating our build times", and strategically moving the json using bits out of widely included headers. It turns out that putting literally any metrics whatsoever into the build had immediate and predictable results. Results are 1382.5s frontend time -> 1175.4s frontend time, back end time approximately invariant. Related: https://git.lix.systems/lix-project/lix/issues/159 Change-Id: I7edea95c8536203325c8bb4dae5f32d727a21b2d
2024-03-25Merge pull request #8817 from iFreilicht/flake-update-lock-overhaulThéophane Hufschmitt
Overhaul `nix flake update` and `nix flake lock` UX (cherry picked from commit 12a0ae73dbb37becefa5a442eb4532ff0de9ce65) Change-Id: Iff3b4f4235ebb1948ec612036b39ab29e4ca22b2
2024-03-25Overhaul completions, redo #6693 (#8131)John Ericson
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-17Delete hasPrefix and hasSuffix from the codebaseJade Lovelace
These now have equivalents in the standard lib in C++20. This change was performed with a custom clang-tidy check which I will submit later. Executed like so: ninja -C build && run-clang-tidy -checks='-*,nix-*' -load=build/libnix-clang-tidy.so -p .. -fix ../tests | tee -a clang-tidy-result Change-Id: I62679e315ff9e7ce72a40b91b79c3e9fc01b27e9
2024-03-04Merge pull request #8931 from fricklerhandwerk/nix3-config-optionsThéophane Hufschmitt
do not show configuration override flags for each command (cherry picked from commit f89b84919c1a5c796512c50311821e7779b3678b) Change-Id: Ib98b739bd6c9a1e94f94a78a47d84d72e435e7c0
2023-08-11MultiCommand::toJSON: Fix use-after-moveYorick van Pelt
2023-06-18Create nlohmann serializers for `std::optional` and useJohn Ericson
This is somewhat tricky.
2023-04-03Stuctured command stabilityJohn Ericson
Prior to this, there was an ad-hoc whitelist in `main.cc`. Now, every command states its stability. In a future PR, we will adjust the manual to take advantage of this new information in the JSON. (It will be easier to do that once we have some experimental feature docs to link too; see #5930 and #7798.)
2023-03-20Fix handling of experimental features mid-parseJohn Ericson
If we conditionally "declare" the argument, as we did before, based upon weather the feature is enabled, commands like nix --experimental-features=foo ... --thing-gated-on-foo won't work, because the experimental feature isn't enabled until *after* we start parsing. Instead, allow arguments to also be associated with experimental features (just as we did for builtins and settings), and then the command line parser will filter out the experimental ones. Since the effects of arguments (handler functions) are performed right away, we get the required behavior: earlier arguments can enable later arguments enabled! There is just one catch: we want to keep non-positional flags...non-positional. So if nix --experimental-features=foo ... --thing-gated-on-foo works, then nix --thing-gated-on-foo --experimental-features=foo ... should also work. This is not my favorite long-term solution, but for now this is implemented by delaying the requirement of needed experimental features until *after* all the arguments have been parsed.
2023-02-10Completions::add use libutil trim()Philipp Jungkamp
2023-02-10Infer short completion descriptions for commandline flagsPhilipp Jungkamp
Descriptions for commandline flags may not include newlines and should be rather short for display in a shell. Truncate the description string of a flag on '\n' or '.' to and add an ellipsis if needed.
2022-10-22Fix C++20 warningsGraham Bennett
2022-09-13Trim option descriptionsEelco Dolstra
This removes unintended blank lines in Markdown when the description is a multiline string literal.
2022-07-11Fix flake input completion for `InstallablesCommand`sNaïm Favier
Defers completion of flake inputs until the whole command line is parsed so that we know what flakes we need to complete the inputs of. Previously, `nix build flake --update-input <Tab>` always behaved like `nix build . --update-input <Tab>`.
2022-04-19Merge pull request #6128 from ncfavier/fix-completionEelco Dolstra
Shell completion improvements
2022-03-07Perform tilde expansion when completing flake fragmentsNaïm Favier
Allows completing `nix build ~/flake#<Tab>`. We can implement expansion for `~user` later if needed. Not using wordexp(3) since that expands way too much.
2022-03-07Make completeDir follow symlinksNaïm Favier
Allows completing `nix why-depends /run/cur<Tab>` to /run/current-system
2022-03-07Ensure the completion marker is not processed beyond completionNaïm Favier
I was surprised to see an error mentioning ___COMPLETE___ when trying to complete a flag argument that had no completer implemented
2022-03-07Implement a suggestions mechanismregnat
Each `Error` class now includes a set of suggestions, and these are printed by the top-level handler.
2022-02-25Remove std::string alias (for real this time)Eelco Dolstra
Also use std::string_view in a few more places.
2021-12-22Don't insert spaces when completing attribute pathsNaïm Favier
2021-09-13nix --help: Display help using lowdown instead of manEelco Dolstra
Fixes #4476. Fixes #5231.
2021-02-26nix flake update: Recreate the lock fileEelco Dolstra
This is probably what most people expect it to do. Fixes #3781. There is a new command 'nix flake lock' that has the old behaviour of 'nix flake update', i.e. it just adds missing lock file entries unless overriden using --update-input.
2021-02-24Respect command registrations in plugins.Shea Levy
2021-02-24Initialize plugins after handling initial command line flagsShea Levy
This is technically a breaking change, since attempting to set plugin files after the first non-flag argument will now throw an error. This is acceptable given the relative lack of stability in a plugin interface and the need to tie the knot somewhere once plugins can actually define new subcommands.
2021-02-07Support --no-net for backwards compatibilityEelco Dolstra
2021-01-25Group common optionsEelco Dolstra
2021-01-25Group subcommands by categoryEelco Dolstra
2021-01-25Make '--help' do the same as 'help' (i.e. show a manpage)Eelco Dolstra
2020-12-23Command: Remove examples()Eelco Dolstra
2020-12-21Move doc() to ArgsEelco Dolstra
2020-12-03Add deprecated aliases for renamed commandsEelco Dolstra
2020-10-09Completions::add(): Guard against newlinesEelco Dolstra
2020-10-09Add a description in the completion outputsregnat
Make nix output completions in the form `completion\tdescription`. This can't be used by bash (afaik), but other shells like zsh or fish can display it along the completion choices
2020-10-06Remove static variable name clashesEelco Dolstra
This was useful for an experiment with building Nix as a single compilation unit. It's not very useful otherwise but also doesn't hurt...
2020-08-20Allow 'nix' subcommands to provide docs in Markdown formatEelco Dolstra
2020-08-17Start generation of the nix.1 manpageEelco Dolstra
2020-08-17Add 'nix dump-args' to dump all commands/flags for manpage generationEelco Dolstra
2020-07-01Don't process an option if any of its arguments need completionEelco Dolstra
2020-06-26Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-18Merge branch 'enum-class' into no-hash-type-unknownJohn Ericson
2020-06-18Merge remote-tracking branch 'upstream/master' into enum-classJohn Ericson
2020-06-17Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-11Merge remote-tracking branch 'upstream/master' into errors-phase-2Ben Burdette
2020-06-04Merge remote-tracking branch 'origin/master' into flakesEelco Dolstra
2020-06-04Make 'nix dev-shell' a deprecated alias for 'nix develop'Eelco Dolstra