Commit Graph

26 Commits

Author SHA1 Message Date
Jun Wu
5dd0629478 cliparser: add an error type about illegal alias
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
2019-07-29 19:35:28 -07:00
Jun Wu
e2dc067ee0 cliparser: change "visited" in "expand_aliases" to HashSet
Summary: `visited` does not need to be a HashMap to detect circular aliases.

Reviewed By: kulshrax

Differential Revision: D16530517

fbshipit-source-id: a27ee97ab8a80e6232600dbc062b0cac701c92a8
2019-07-29 19:35:28 -07:00
Jun Wu
ba96820bef cliparser: remove another unnecessary condition
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
2019-07-29 19:35:27 -07:00
Jun Wu
b443b60df1 cliparser: remove an unnecessary condition
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
2019-07-29 19:35:27 -07:00
Jared Bosco
01465ad1d5 hgmain: replace hg root entirely with a native implementation
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
2019-07-26 20:38:50 -07:00
Jared Bosco
6bf5f920ee hgmain: implement native hg root command with new dispatch library
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
2019-07-26 20:38:50 -07:00
Mateusz Kwapich
5ce2387e15 fix the problem with flags starting from --no
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
2019-07-26 14:13:11 -07:00
Mateusz Kwapich
073fcf2078 show the problem with handling args prefixed with 'no-'
Summary: context: T47908435

Reviewed By: quark-zju

Differential Revision: D16519889

fbshipit-source-id: 952df74f381af2c527cecabe0cd804e7a51bed10
2019-07-26 14:13:11 -07:00
Jared Bosco
089e77642a dispatch: replace final fancyopts call with native rust
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
2019-07-20 01:06:35 -07:00
Jared Bosco
f56b7f2a62 cliparser: add more robust error handling for parsing failure cases
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
2019-07-20 01:06:35 -07:00
Jared Bosco
939b3f5c57 cliparser: change FlagDefinition to use Cow to support static and dynamic lifetimes
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
2019-07-20 01:06:35 -07:00
Jared Bosco
ae89e32851 cliparser: expose method to perform alias expansion on arguments
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
2019-07-20 01:06:34 -07:00
Jared Bosco
5f02e5cd5c dispatch: replace _parse's call to fancyopts with native code
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
2019-07-20 01:06:33 -07:00
Jared Bosco
40ca990aac dispatch: replace a fancyopts call with native code
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
2019-07-20 01:06:33 -07:00
Jared Bosco
ee1fcc3d2d bindings: create cliparser native binding to replace fancyopts early parsing
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
2019-07-20 01:06:32 -07:00
Jared Bosco
9984985969 cliparser: port python global flags to rust definition
Summary: The global flags currently in Python should be ported to Rust definitions

Reviewed By: quark-zju

Differential Revision: D15782273

fbshipit-source-id: 1cfdb3bbab946d18dc3c899163286e30fa69c2c7
2019-07-20 01:06:32 -07:00
Jared Bosco
b41f91b70d cliparser: allow flags to be partial matched by prefix
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
2019-07-20 01:06:32 -07:00
Jared Bosco
ef61b6fae9 cliparser: add skeleton code for command and command builder
Summary: Initial design / skeleton code for command::Command and command::CommandBuilder which is unimplemented

Reviewed By: quark-zju

Differential Revision: D15588927

fbshipit-source-id: 193d3d2aaae98a252e13d5b1e655cf93d7ce801e
2019-07-20 01:06:31 -07:00
David Tolnay
f7011a3993 rust: Head start on some upcoming warnings
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
2019-07-12 00:55:53 -07:00
Andres Suarez
e936dde821 Apply rustfmt to all rust files
Reviewed By: jsgf

Differential Revision: D14578283

fbshipit-source-id: 9b4a7b1fd445fd033b64c6af04ee52b27eefb616
2019-07-10 20:18:48 -07:00
Jared Bosco
c04b8fe56b cliparser: stop trimming args and removing program name from args
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
2019-06-10 10:19:53 -07:00
Jared Bosco
f6929cd397 cliparser: refactor multiplicity and valuetype into a unified type
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
2019-06-10 10:19:52 -07:00
Jared Bosco
628c8f95f1 cliparser: update documentation for better rendering with cargo doc
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
2019-05-30 18:03:36 -07:00
Jared Bosco
00b5fcd271 cliparser: create parser that can parse out flag definitions from command line arguments
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
2019-05-30 18:03:36 -07:00
Jared Bosco
f1332b8fa4 cliparser: create a flag definition for command line parsing
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
2019-05-30 18:03:36 -07:00
Jared Bosco
d94dde74b2 cliparser: create bare cliparser library
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
2019-05-30 14:42:37 -07:00