Summary: The field not only decides the type, but also provides the default.
Reviewed By: farnz
Differential Revision: D16700308
fbshipit-source-id: 73aec2c227c7ce6f5b19aa5ae093f37f0b265cd3
Summary:
This helps removing references. The internal structure of `Parser` is changed a
bit to avoid storing `Flag` copies.
Reviewed By: farnz
Differential Revision: D16700316
fbshipit-source-id: 01d66feb8bd5cc2fa9394b3635f97e098143597d
Summary: `char` is only 4 bytes. Using the concrete type is faster than a reference.
Reviewed By: farnz
Differential Revision: D16700306
fbshipit-source-id: d7f198238005ec5a0061ed79724b795cd1e5077b
Summary:
This is a step towards:
- Getting rid of `<'a>` lifetime from `Flag` and `FlagDefinition`.
- Getting rid of `FlagDefinition` - it's too similar to `Flag` and is not
really a dedicated type (it's a type alias).
Reviewed By: farnz
Differential Revision: D16700313
fbshipit-source-id: b517d5203bcd1eff3381c7c6ae1020965bd135b0
Summary:
It does not make much sense for a flag to not have a description, and there are
no users depending on that. Therefore drop the `Option`.
Reviewed By: farnz
Differential Revision: D16700318
fbshipit-source-id: 4566cf339088ba69b64dd8a316a9f36fb1fac81b
Summary:
Leading underscores are uncommon in Rust. Since `parse_args` just calls `_parse`,
merge `_parse` into `parse_args`.
Input types of `parse_args` are changed a bit to be more flexible.
Reviewed By: farnz
Differential Revision: D16700314
fbshipit-source-id: 6e13ca7796cbb535fef79e3a723002bf7ef8d6f6
Summary: The options decides how the parser works. It is not opening anything.
Reviewed By: farnz
Differential Revision: D16700310
fbshipit-source-id: c0ab69f9d8c50664dc157ef0eb0f12ee1533e81d
Summary:
This removes the warning:
warning: cliparser/Cargo.toml: `default-features = [".."]` was found in [features]. Did you mean to use `default = [".."]`?
Reviewed By: sfilipco
Differential Revision: D16672732
fbshipit-source-id: 2c7478c54f0302113d4e065f88631c096757e829
Summary:
Fix the regression caused by D16557266 on error message. The fix is not the
most efficient, though. But it should restore the behavior.
Reviewed By: singhsrb
Differential Revision: D16557654
fbshipit-source-id: 2eb6956f99c931f94201b875c8bebb2219a794f0
Summary:
When doing command name prefix match, if there are a unique match for non-debug
commands, use it. This solves `hg d` regression.
Note: we cannot simply use `starts_with("debug")` to test debug commands. That
is because debug commands can have aliases (ex. `debug|dbsh` as the command
name definition, and `dbsh` is also a debug command that does not starts with
`debug`). Therefore it gets a bit complex.
Reviewed By: kulshrax
Differential Revision: D16557266
fbshipit-source-id: 42d814940c9217d9e554bd0fe2769a53e0ee467f
Summary: Suggested by kulshrax, `I` and `l` are harder to distinugish. Rename it to clarify.
Reviewed By: kulshrax
Differential Revision: D16556868
fbshipit-source-id: 5892f0730f5205534851c5f7c024ff98f751423d
Summary: This just makes the code slightly more confident.
Reviewed By: kulshrax
Differential Revision: D16556871
fbshipit-source-id: 5304c3e60c80242974d35a53aace84f829418bb8
Summary: This will be used to accurately replace the command line arguments.
Reviewed By: kulshrax
Differential Revision: D16556870
fbshipit-source-id: efb77a0da17c436e0123354746ba85201813992a
Summary: Expand `$1`, `$2` etc. in aliases. There are users depending on this behavior.
Reviewed By: kulshrax
Differential Revision: D16531016
fbshipit-source-id: fed735339adc82c4f52b74c4c4d62818bc047809
Summary:
This avoids calculating the full alias map, and provides more flexibility (ex.
the function can take care of `defaults` handling).
Reviewed By: kulshrax
Differential Revision: D16530514
fbshipit-source-id: 63558da5c9af36b2f8bc7689174fed71593a8186
Summary:
Make `expand_prefix` a public API to expand a command prefix to a full command
name.
Make Python binding handle the `strict` flag so `cliparser` does not have to.
This avoids calculation of `command_map` if strict is True.
Reviewed By: kulshrax
Differential Revision: D16530520
fbshipit-source-id: 5bf9c9f74ae074eac5e350a4db0ebc43f286cebf
Summary: This is the first step to support expanding things like `$1` in aliases.
Reviewed By: kulshrax
Differential Revision: D16530515
fbshipit-source-id: 3e81c92c2e2021b99815974f53286ec789ba0733
Summary:
The loop body can be changed to reduce some identation.
This changes the behavior a bit - an alias expanding to an emtpy string is now
an error. That's consistent with the original behavior.
Reviewed By: kulshrax
Differential Revision: D16530516
fbshipit-source-id: 3f5c2ebe9d8d1727cac706e4ff11f2678567c525
Summary:
When the alias cannot be split via shlex::split, raise an error directly
instead of silently ignoring it and fallback to Python error handling.
Reviewed By: kulshrax
Differential Revision: D16530519
fbshipit-source-id: d81534b198555b256f062dc4e6520fa40ace7700
Summary: `visited` does not need to be a HashMap to detect circular aliases.
Reviewed By: kulshrax
Differential Revision: D16530517
fbshipit-source-id: a27ee97ab8a80e6232600dbc062b0cac701c92a8
Summary: The code was added by D16497604. It does not seem necessary. Therefore remove it.
Reviewed By: kulshrax
Differential Revision: D16553455
fbshipit-source-id: 2d8a9bc54c975d10a9357360feac86b6ec78f794
Summary:
The code tests if `arg` (aka. command name) starts with `-`. That does not need
special handling because normally a command name does not start with `-`.
Reviewed By: kulshrax
Differential Revision: D16530518
fbshipit-source-id: 0bd2cdc04a27013ad856e86ee9e0e2705bf5bd57
Summary: Replace original Python `hg root` implementation with Rust `hg root` implemented with the new command line dispatch library.
Reviewed By: quark-zju
Differential Revision: D16497604
fbshipit-source-id: e3d0e60d4bd4203897260c16e070ca3768ff1d22
Summary:
Implement `hg root` in Rust with the `clidispatch` library as well as adding all current Python commands so that prefix matching still works as expected.
This diff does not remove `hg root` from Python or expose native command documentation to Python, which will be the next diff.
Reviewed By: quark-zju
Differential Revision: D16454053
fbshipit-source-id: 78a9c70aeefb9adbb85c77001b15eab652417b2c
Summary:
When we had a "--no-something" flag registered providing "--something"
did the same thing as providing "--no-something" which is highly undesirable
(see task)
Reviewed By: quark-zju
Differential Revision: D16520376
fbshipit-source-id: 9d407b830067d095abdbd9c0cee674f424ffc0f9
Summary: Remove final fancyopts call to have all python parsing being done through native rust codepath, as well as clean-up some deprecated flags that would be special handling.
Reviewed By: quark-zju
Differential Revision: D16156284
fbshipit-source-id: ec5ccaeb982c78426e12ff1d7342b4ea6653e98e
Summary: Add errors and map them to python exceptions to emulate the original python error handling behavior.
Reviewed By: quark-zju
Differential Revision: D16136571
fbshipit-source-id: eb999162cad040566e30b460f2b873efb05fc67a
Summary: To support 'static and dynamic lifetimes the FlagDefinition will have a Cow<'a, str> allowing the API to remain the same and still be used with strings passed from python.
Reviewed By: quark-zju
Differential Revision: D16136148
fbshipit-source-id: 670925549919a0965287b264704150f6ab638a18
Summary:
Alias expansion originally occurs in mercurial through a chain of command handlers that point at their alias.
Now, aliases can be fully expanded early on into parsing to only resolve actual commands and not have to follow a chain of executions.
Reviewed By: quark-zju
Differential Revision: D16059122
fbshipit-source-id: cf28fba4a131ab29ceda87bc3e90d7a434e06625
Summary: Replacing another fancyopts call to be parsed by native Rust code. This diff introduces slightly hacky feeling behavior in order to handle cycles and resolving aliases, but will be fixed in a follow-up diff where Rust will fully expand the aliases completely removing the need for this confusing alias resolving, chaining, and execution.
Reviewed By: quark-zju
Differential Revision: D15902758
fbshipit-source-id: 11d9a479989a23de09bf96f8020d2fded6c06351
Summary: Replace the next usage of fancyopts in dispatch.py with native rust code, and ensure all tests pass with this replacement.
Reviewed By: quark-zju
Differential Revision: D15857997
fbshipit-source-id: ec8722bfe661731a14cb324e97846f861bd60bc8
Summary:
The current Python parsing library fancyopts does an early parse for global flags, as well as slightly different logic for parsing out flags.
Switching this fancyopts call should allow fancyopts to be completely replaced by the native code path, and start using Rust parsing for hg.
This enforces command line arguments to be utf8. At Facebook, our `hg` wrapper already crashes if that is not the case. So it shouldn't cause new issues.
Reviewed By: quark-zju
Differential Revision: D15837079
fbshipit-source-id: 95634ebc814f8865960181f23282e5283068057c
Summary: The global flags currently in Python should be ported to Rust definitions
Reviewed By: quark-zju
Differential Revision: D15782273
fbshipit-source-id: 1cfdb3bbab946d18dc3c899163286e30fa69c2c7
Summary:
Flags should be able to be matched partially by a prefix-match.
If a given prefix returns more than one possible Flag, it is therefore ambiguous and should not choose for the user.
An exact match should always take precedence. A partial match should be tried in the event the argument is not an exact match.
Reviewed By: quark-zju
Differential Revision: D15749936
fbshipit-source-id: 26e699616a1b3fa6871fb50cc6914f916701004c
Summary:
This diff sets two Rust lints to warn in fbcode:
```
[rust]
warn_lints = bare_trait_objects, ellipsis_inclusive_range_patterns
```
and fixes occurrences of those warnings within common/rust, hg, and mononoke.
Both of these lints are set to warn by default starting with rustc 1.37. Enabling them early avoids writing even more new code that needs to be fixed when we pull in 1.37 in six weeks.
Upstream tracking issue: https://github.com/rust-lang/rust/issues/54910
Reviewed By: Imxset21
Differential Revision: D16200291
fbshipit-source-id: aca11a7a944e9fa95f94e226b52f6f053b97ec74
Summary: Parser::parse_args would skip the first argument assuming it was the program name, as well as trimming arguments. This makes it have both inflexible and incorrect behavior, such as a client wanting to parse only some of the arguments, or an end-user wanting spaces to be maintained correctly.
Reviewed By: quark-zju
Differential Revision: D15698765
fbshipit-source-id: 119b7afb25e46332649ab121bef3504e79fa3ee9
Summary:
In order to be more in line with the current Python CLI parser, Parser::Multiplicity and Parser::ValueType is merged into a singular Parser::Value that supports default values, no value, as well as accepting values from the user in a type-safe way.
API / design is still unstable so documentation wasn't added just changed to allow doc tests to pass with the new type.
Reviewed By: quark-zju
Differential Revision: D15583997
fbshipit-source-id: 0c7d9dd4afa3579ca41008c4c427b90f2098100a
Summary: Ported the global constant flags from Python code in scm/hg/edenscm/mercurial/commands/__init__.py to the new Rust definitions
Reviewed By: quark-zju
Differential Revision: D15487764
fbshipit-source-id: fd4a0ec77779055b96741888f80e92d41dd430d5
Summary: Parser is able to take command line arguments and parse them into found flag definitions and their related values ( if specified ). This is the 'first' pass at grabbing all found static flags.
Reviewed By: quark-zju
Differential Revision: D15487686
fbshipit-source-id: 6a40947078eb4bf0683a6f168c21d234a40939ef
Summary: Flag definition is used for parsing flags on the command line, as well as allowing the configuration of flags that may accept values, have short names, long names, etc.
Reviewed By: quark-zju
Differential Revision: D15487487
fbshipit-source-id: 7b41b027ae4770b86c2e19973e57ac41f717cfc8
Summary: Initial commit for the cliparser command line argument parsing library. Can be tested with buck, or cargo.
Reviewed By: quark-zju
Differential Revision: D15487278
fbshipit-source-id: 5f3f65e58a815d2c408e38a3eb9e9981086c6715