Commit Graph

15 Commits

Author SHA1 Message Date
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