Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Refactoring the cli #11702

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Refactoring the cli #11702

wants to merge 2 commits into from

Conversation

wesrer
Copy link

@wesrer wesrer commented May 12, 2020

This PR refactors the cli macros with structopt and adds an inbuilt configuration generator that can save the current flags into a custom toml for future use.

Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run this I see a the argument list divided into FLAGS and OPTIONS where before this was not the case. I don't think that was intentional but I'm not sure what the plan is there: can you elaborate?
The list of flags/options does not contain the helpful "labels" we used to have, e.g.:

Snapshot Options:
    --no-periodic-snapshot
        Disable automated snapshots which usually occur once every 5000 blocks.

    --snapshot-threads=[NUM]
        Enables multiple threads for snapshots creation.

…are now printed as separate items far apart in the long list of options. Not sure how capable structopt is at grouping options together but I think it'd be important that we keep that.

)]
// FIXME: The original parser implementation had this as `Option<Vec<String>>` but this is not
// supported by structopt yet, referring to issue
// [#364](https://github.com/TeXitoi/structopt/issues/364)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's not quite how I read #364 – it seems to be quirky but not unsupported. Can you elaborate?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty awkward to distinguish in the CLI flag setting regardless so I'd treat empty list as None.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the empty list was treated equivalently to None in the previous version, and it's the same in this version. All the previous tests are passing, so unless this was a case not tested, we are good

parity/cli/subcommands.rs Outdated Show resolved Hide resolved
parity/cli/subcommands.rs Outdated Show resolved Hide resolved
help = "Take a snapshot at the given block, which may be an index, hash, or latest. Note that taking snapshots at non-recent blocks will only work with --pruning archive"
)]
pub at: String,
// FIXME: check if the default is correct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you mean "default"? I don't think this should have a default (and it's required).

parity/cli/subcommands.rs Outdated Show resolved Hide resolved
@@ -241,10 +241,5 @@ pub fn start<Cr, Rr>(
Cr: Fn(String) + 'static + Send,
Rr: Fn() + 'static + Send
{
let deprecated = find_deprecated(&conf.args);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is does deprecation work in this new version? It'd be good to have some internal documentation on how to best add/deprecate/remove cli flags/options/subcommands somewhere.

@wesrer wesrer marked this pull request as ready for review May 28, 2020 09:45
@wesrer wesrer requested a review from vorot93 May 28, 2020 09:45
Copy link

@vorot93 vorot93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. I'm currently digging the CLI story a bit deeper, and this PR with a few modifications may actually become mergeable short-term.

term_size = "0.3"
textwrap = "0.11.0"
toml = "0.5.6"
rust-embed = "5.5.1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any strong reason not to use standard include family macros?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found rust-embed to have a cleaner api. I believe internally, it expands to include macros

parity/cli/args.rs Outdated Show resolved Hide resolved
)]
// FIXME: The original parser implementation had this as `Option<Vec<String>>` but this is not
// supported by structopt yet, referring to issue
// [#364](https://github.com/TeXitoi/structopt/issues/364)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty awkward to distinguish in the CLI flag setting regardless so I'd treat empty list as None.

parity/cli/globals.rs Outdated Show resolved Hide resolved
parity/cli/globals.rs Outdated Show resolved Hide resolved
parity/cli/globals.rs Outdated Show resolved Hide resolved
parity/cli/args.rs Outdated Show resolved Hide resolved
parity/cli/config.rs Outdated Show resolved Hide resolved
parity/cli/globals.rs Outdated Show resolved Hide resolved
parity/cli/globals.rs Outdated Show resolved Hide resolved
@wesrer wesrer requested a review from vorot93 June 1, 2020 12:11
@wesrer
Copy link
Author

wesrer commented Jun 3, 2020

There are a few edge cases that are worth mentioning (will keep editing this comment with further findings):

  • If there is a default config that the user is using, and it has one of the boolean flags marked true, but for this instance they want it to be false, there is no way of expressing that since boolean flags are marked true if present and if absent uses the value of the default config.

@dvdplm
Copy link
Collaborator

dvdplm commented Jun 4, 2020

* If there is a default config that the user is using, and it has one of the boolean flags marked true, but for this instance they want it to be false, there is no way of expressing that since boolean flags are marked true if present and if absent uses the value of the default config.

Not 100% sure I understand what you mean here. What is a "default config that the user is using"? and what is an "instance" in this context?

Do you mean that a user has prepared a config "template" of sorts that they use for several nodes and wish to override just a few option for one particular node instance? Can't they just --foo=false to override the foo: false in the config file?

@wesrer
Copy link
Author

wesrer commented Jun 4, 2020

* If there is a default config that the user is using, and it has one of the boolean flags marked true, but for this instance they want it to be false, there is no way of expressing that since boolean flags are marked true if present and if absent uses the value of the default config.

Not 100% sure I understand what you mean here. What is a "default config that the user is using"? and what is an "instance" in this context?

Do you mean that a user has prepared a config "template" of sorts that they use for several nodes and wish to override just a few option for one particular node instance? Can't they just --foo=false to override the foo: false in the config file?

So essentially this version comes with a built in config generator flag that stores current flags into a file for future use - the assumption being people's configuration needs remain the same a majority of the time. However, once of twice, they may want to run a different config with a few altered flags - the usual way to do this is to just use their saved config and override flags, which is when this case arises. The user cannot --flag=false because boolean flags are interfaced as either present or absent. Thus --flag is true, and not having that option in the argument list is considered false. But in our case, we don't assume all absent flags are false, but rather they are to take the value of the provided config, which is where the problem arises.

@dvdplm
Copy link
Collaborator

dvdplm commented Jun 4, 2020

The user cannot --flag=false because boolean flags are interfaced as either present or absent.

That is pretty surprising (not a good thing when it comes to UX). I think the user expectation is that the CLI should work (very) similarly to how it worked before and any deviation from that should be a clear improvement. New users will likely expect the openethereum CLI to work like most other command line tools, where --foo=false works as expected.

At this point I am not sure I understand what the idea is with this PR. Perhaps now is a good time to step back and write up a proper description on what the plan is, and how the CLI UI will work?

@sorpaas sorpaas added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M5-binaries 📦 External binaries (ethkey, ethstore, ethvm, etc.) labels Jul 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M5-binaries 📦 External binaries (ethkey, ethstore, ethvm, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants